http - python-requests - Sending via POST form with square brackets names doesn't work -
I was trying to send server [key1] = val1 and test [key2] = val42 to a server via I am Related HTML:
& lt; Input type = "text" name = "test [key1]" value = "val1" /> & Lt; Input type = "text" name = "test [key2]" value = "val42" />
(By the way, I would like to know the correct name for this type of form.)
& gt; & Gt; & Gt; Import request, JSNA & gt; & Gt; & Gt; Parameters = {'test': {'key1': 'val1', 'key2': 'val42'}}} gt; & Gt; & Gt; R = requests.post ('http://httpbin.org/post', data = parameter) & gt; & Gt; & Gt; Json.loads (r.text) ['form'] {u'test ': [u'key2', u'key1 ']}
The post data has been flattened, We got the keys, but the values were lost val1 and val42
I thought the embedded key was not so is.
You have to type the parameter
with square brackets.
& gt; & Gt; & Gt; Params = {'test [key1]': 'val1', 'test [key2]': 'val42'} & gt; & Gt; & Gt; R = requests.post ('http://httpbin.org/post', data = parameter) & gt; & Gt; & Gt; Json.loads (r.text) ['form'] {u'test [key1] ': u'val1', u'test [key2] ': u'val42'}
Hope this will help someone.
Comments
Post a Comment