-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"No POST data" in error report #7953
Comments
Any progress on this issue? I have the same problem. |
I can also confirm this issue, and it makes it a little bit hard to trace back errors Here is a discussion related to this problem |
At this point I am convinced DRF is a dead project |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I still think this is an important feature, please don't close this issue. |
I agree. |
I'm also having this issue. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I still think this is an important feature, please don't close this issue. |
It is because django dose not parse body of application/json to request.POST field.You can convert json string to dict by yourself, like this: |
some code snippet:
and the message is ...\n\nGET: No GET data\n\nPOST:\nusername = 'python1'\npassword = '123456'\n\nFILES: No FILES data... |
Thanks, @donghj2000, this is awesome, but I still think this should be a built-in feature. |
Glad to help you. I have not found why they didn't do so. Another workaround is to use Middleware:
|
This snippet has an issue where it assumes the JSON is an object and will fail on any other valid JSON value |
It seems to be a bug exactly, but request.POST is initialized as a QueryDict(django.http.request.py->class HttpRequest) ,so I don't know how to deal with other JSON type... |
no. it has 4 new more maintainers now. btw would love to see a failing test case to find out the fix for the problem. who is up for that? here is a comment pointing to the direction #1671 (comment) |
I can do this but I'd like to know the definition of the problem from your side. @donghj2000 said,
Do you agree that it is a problem and |
One workaround is to get DRF's APIView class to set the request POST field after parsing the request. This can be achieved by overriding initialize_request on the APIView (or ViewSet) class:
Note however that Django's decorator sensitive_post_parameters will not work with DRF's views as it is expecting Django's Request object, so you might want to set |
Checklist
Description
I'm using Django 3.1.7 & DRF 3.12.2.
When an exception occurs in a
ViewSet
, Django automatically sends an email to the administrator.The problem is that the POST data is always empty in this email:
Instead, I expect to see the JSON payload that was sent in the request body.
I added a breakpoint in
django.utils.log.AdminEmailHandler.emit()
, and I can confirm thatrequest.POST
is empty.But on the other hand, I'm sure that
request.data
was not empty in theViewSet
.I verified that the request's
Content-Type
andX-Requested-With
are correctly set.The only non-standard middlewares I use are corsheaders and admin_reorder; I don't think they are related to this problem.
The text was updated successfully, but these errors were encountered: