I have a Django App that accept images through REST-api. I tested the api using POSTMAN locally, it's working perfect with image uploads. Later I deployed it on OpenShift V3 and when I tried the same for uploading process using POSTMAN , it's saying
Server Traceback
Environment:
Request Method: POST
Request URL: http://django-psql-persistent-sampledjangoex.44fs.preview.openshiftapps.com/myapp/sample/
Django Version: 1.9
Python Version: 3.5.1
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'debug_toolbar',
'welcome',
'rest_framework')
Installed Middleware:
('debug_toolbar.middleware.DebugToolbarMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware')
Traceback:
File "/opt/app-root/src/.local/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
174. response = self.process_exception_by_middleware(e, request)
File "/opt/app-root/src/.local/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
172. response = response.render()
File "/opt/app-root/src/.local/lib/python3.5/site-packages/django/template/response.py" in render
160. self.content = self.rendered_content
File "/opt/app-root/src/.local/lib/python3.5/site-packages/rest_framework/response.py" in rendered_content
71. ret = renderer.render(self.data, media_type, context)
File "/opt/app-root/src/.local/lib/python3.5/site-packages/rest_framework/renderers.py" in render
104. separators=separators
File "/opt/rh/rh-python35/root/usr/lib64/python3.5/json/__init__.py" in dumps
237. **kw).encode(obj)
File "/opt/rh/rh-python35/root/usr/lib64/python3.5/json/encoder.py" in encode
199. chunks = self.iterencode(o, _one_shot=True)
File "/opt/rh/rh-python35/root/usr/lib64/python3.5/json/encoder.py" in iterencode
257. return _iterencode(o, 0)
File "/opt/app-root/src/.local/lib/python3.5/site-packages/rest_framework/utils/encoders.py" in default
64. return super(JSONEncoder, self).default(obj)
File "/opt/rh/rh-python35/root/usr/lib64/python3.5/json/encoder.py" in default
180. raise TypeError(repr(o) + " is not JSON serializable")
Exception Type: TypeError at /myapp/sample/
Exception Value: b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xdb\x00C\x00\x06\x04\x05\x06\x05\x04\x06\x06\x05\x06\x07\x07\x06\x08\n' is not JSON serializable
Here is the source Code of the Program
Note: I can do uploading process through DRF-Browsable api
First of all I would say thanks to @Raz. Actually the tool POSTMAN caused the issue. I tested the OpenShift-v3 api using Python's Request library. It's worked :)
Code I used;