Skip to content

Request content-type #30

Open
Open

Description

@odinuv

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.

Activity

  1. pocin commented on Sep 1, 2017

    @pocin
    Contributor

    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?

  2. odinuv commented on Sep 3, 2017

    @odinuv
    MemberAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions