#23773: Client().post("/someurl",data="", content_type='text/plain') results in request.body = {} -------------------------------+-------------------------------------- Reporter: isparks | Owner: nobody Type: Bug | Status: new Component: HTTP handling | Version: 1.7 Severity: Normal | Resolution: Keywords: | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------+-------------------------------------- Changes (by bmispelon):
* needs_better_patch: => 0 * needs_tests: => 0 * needs_docs: => 0 Old description: > If you want to access request.body in a handler function to get the raw > posted data and the value posted was the empty string "" with a content > type of text/plain then what appears in request.body is a string > representing an empty dictionary {} due to this line in client.py in the > RequestFactory class. > > def post(self, path, data=None, content_type=MULTIPART_CONTENT, > secure=False, **extra): > "Construct a POST request." > > post_data = self._encode_data(data or {}, content_type) # <-- > Problem line > > Here data is replaced with a dictionary before being passed to encoding > but what I would expect to end up in request.body is the original empty > string for a text/plain request. New description: If you want to access request.body in a handler function to get the raw posted data and the value posted was the empty string `""` with a content type of text/plain then what appears in request.body is a string representing an empty dictionary `{}` due to this line in client.py in the RequestFactory class. {{{#!python def post(self, path, data=None, content_type=MULTIPART_CONTENT, secure=False, **extra): "Construct a POST request." post_data = self._encode_data(data or {}, content_type) # <-- Problem line }}} Here data is replaced with a dictionary before being passed to encoding but what I would expect to end up in request.body is the original empty string for a text/plain request. -- -- Ticket URL: <https://code.djangoproject.com/ticket/23773#comment:1> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/065.81c0b336f6bbb87b7b0f5614d34de535%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.