QuickStart documentation error
httpbin post has a header item '"X-Amzn-Trace-Id" which causes an result which is contrary to the documentation.
Quickstart documentation
"More complicated POST requests"
payload_tuples = [('key1', 'value1'), ('key1', 'value2')]
r1 = requests.post('https://httpbin.org/post', data=payload_tuples)
payload_dict = {'key1': ['value1', 'value2']}
r2 = requests.post('https://httpbin.org/post', data=payload_dict)
print(r1.text)
{
...
"form": {
"key1": [
"value1",
"value2"
]
},
...
}
r1.text == r2.text
True
Actual Result
Reproduction Steps
import requests
payload_tuples = [('key1', ' "value1'),('key1', 'value2')]
payload_dict = {'key1': ['value1', 'value2']}
r1 = requests.post('https://httpbin.org/post', data=payload_tuples)
r2 = requests.post('https://httpbin.org/post', data=payload_dict)
r1.text == r2.text
False
r1.json()['form'] == r2.json()['form']
True
Diagnostic Information
pprint.pprint(r1.text) ('{… ' "form": {\n' ' "key1": [\n' ' "value1", \n' ' "value2"\n' ' ]} … ' "X-Amzn-Trace-Id": "Root=1-682cb364-67bf5e846c56c77e24839642"\n' '… }, …
pprint.pprint(r2.text) ('{… ' "form": {\n' ' "key1": [\n' ' "value1", \n' ' "value2"\n' ' ]} … ' "X-Amzn-Trace-Id": "Root=1-682cb30f-208ede8e2eda5cf75cf578ac"\n' ' … }, …
Hi! I noticed that in the Quickstart documentation, the example compares r1.text == r2.text and expects True. However, httpbin.org adds a header ("X-Amzn-Trace-Id") to each response, which changes on every request. This causes the full response text to differ, even if the form data is identical. Instead, I suggest comparing r1.json()['form'] == r2.json()['form'], which correctly returns True when the form data matches. It may be helpful to update the documentation to clarify this, so users are not confused by the differing response text. Thanks!
Hi! I’m new to contributing to Requests and I would like to work on this documentation issue.
I verified the behavior mentioned here — the X-Amzn-Trace-Id header added by httpbin causes r1.text != r2.text even though the form data is identical.
Comparing r1.json()['form'] == r2.json()['form'] returns True, which is the correct way to show equality in the Quickstart example.
I can prepare a small PR to update the Quickstart documentation to clarify this:
- Mention that headers from httpbin (like X-Amzn-Trace-Id) cause the full response text to differ
- Update the example comparison to use
r1.json()['form'] == r2.json()['form']
Please let me know if this is okay to proceed with. Thanks!