Skip to content
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

Request content-type #30

Open
odinuv opened this issue Aug 28, 2017 · 2 comments
Open

Request content-type #30

odinuv opened this issue Aug 28, 2017 · 2 comments

Comments

@odinuv
Copy link
Member

odinuv commented Aug 28, 2017

Currently application/x-www-form-urlencoded is used everywhere. While acceptable, there may be a problem in requests, which are potentially large (such as saving/upadting configurations). There multipart/form-data has to be used. A simple solution is to use multipart/form-data everywhere disregarding a slight performance hit. This is probably important only for POST requests.

@pocin
Copy link
Contributor

pocin commented Sep 1, 2017

check this out, if you pass the data to files argument instead to data, you get the header you want.

>>> import requests
>>> resp = requests.post('https://www.httpbin.org/post', files={'arg1': 'value'})
>>> print(resp.request.headers)
{'Accept': '*/*',
 'Content-Length': '145', 
'Content-Type': 'multipart/form-data; 
boundary=e3afca057d9949529180c87d9352a5e5', 
'Accept-Encoding': 'gzip, deflate',
'Connection': 'keep-alive', 
'User-Agent': 'python-requests/2.12.4'}

>>> resp_data = requests.post('https://www.httpbin.org/post', data={'arg1': 'value'})
>>> print(resp_data.request.headers)
{'Accept': '*/*', 
'Content-Length': '10', 
'Content-Type': 'application/x-www-form-urlencoded', 
'Accept-Encoding': 'gzip, deflate',
 'Connection': 'keep-alive', 
'User-Agent': 'python-requests/2.12.4'}

Does it help in any way?

@odinuv
Copy link
Member Author

odinuv commented Sep 3, 2017

It's more of a design/performance decision. I'd say that if multipart is not significantly slower, let's use multipart everywhere, if it is, we have to identify potentially large requests (save/update configuration strikes me immediately) and use it only there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants