Opened 10 years ago

Closed 10 years ago

#23772 closed Bug (duplicate)

Client().post("/someurl",data="", content_type='text/plain') results in request.body = {}

Reported by: Ian Sparks Owned by: nobody
Component: HTTP handling Version: 1.7
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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.

if data is then data becomes an empty string.

Change History (1)

comment:1 by Baptiste Mispelon, 10 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #23773.

Note: See TracTickets for help on using tickets.
Back to Top