Hey there!
I am working on a file upload functionality and right now I'm stucked on a weird problem. I am always getting the error:
------------------------------------------------------------------------------
{"errors":[{"detail":"Could not satisfy the request Accept header.","status":"406","source":{"pointer":"/data"},"code":"not_acceptable"}]}
------------------------------------------------------------------------------
When I am sending the following request:
------------------------------------------------------------------------------
POST /aposento-fotos/ HTTP/1.1
Host: localhost:8000
Connection: keep-alive
Content-Length: 24364
Accept: application/json,text/javascript
DNT: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryvxVpkZTvYVihDGem
Origin: http://localhost:4200
Sec-Fetch-Site: same-site
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://localhost:4200/
Accept-Encoding: gzip, deflate, br
Accept-Language: pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7 ------------------------------------------------------------------------------
I am getting the following response:
------------------------------------------------------------------------------
HTTP/1.1 406 Not Acceptable
Date: Sat, 31 Oct 2020 01:18:44 GMT
Server: WSGIServer/0.2 CPython/3.6.9
Content-Type: application/vnd.api+json
Vary: Accept, Origin
Allow: GET, POST, HEAD, OPTIONS
X-Frame-Options: DENY
Content-Length: 138
X-Content-Type-Options: nosniff
Access-Control-Allow-Origin: *
------------------------------------------------------------------------------
I have read about the DRF Parsers and tried it all. Nothing is working for my view:
------------------------------------------------------------------------------
class MyUploadViewSet(ModelViewSet):
queryset = Photos.objects.all()
serializer_class = PhotosSerializer
permission_classes = [IsOwnerOrAdminUser]
parser_classes = [MultiPartParser,
FormParser, JSONParser, FileUploadParser]
------------------------------------------------------------------------------
It only works when I use a generic view:
------------------------------------------------------------------------------
class MyUploadView(View):
def get(self, request, **kwargs):
print(request)
print(request.method)
print(request.GET)
def post(self, request, **kwargs):
pass
------------------------------------------------------------------------------
But I want to get it working with the ModelViewSet.
Does anybody know how could I get it working with ModelViewSet? I think it's not working because the request Content-Type, but It was supposed to work with a Parser, right? I am really confused and would appreciate any help.
Thank you in advance.