Python 'requests' module and encoding?
Question: I am doing a simple POST request using the requests module, and testing it
against [httpbin](http://httpbin.org/)

    
    
    import requests
    
    url      = 'http://httpbin.org/post'
    params   = {'apikey':'666666'}
    sample   = {'sample': open('test.bin', 'r')}
    
    response = requests.post( url, files=sample, params=params, verify=False)
    report_info = response.json()
    print report_info
    

I have an issue with the encoding. It is not using `application/octet-stream`
and so the encoding is not correct. From the headers, I see:

    
    
    {
      u'origin': u'xxxx, xxxxxx', 
      u'files': {
                   u'sample': u'data:None;base64,qANQR1DBw..........
    

So, I get `data:None` instead of `data:application/octet-stream` when I try
with `curl`. The file size and encoding is incorrect.

How can I force or check that it is using `application/octet-stream`?


Answer: Sample taken from <http://www.python-
requests.org/en/latest/user/quickstart/#custom-headers>

    
    
    >>> import json
    >>> url = 'https://api.github.com/some/endpoint'
    >>> payload = {'some': 'data'}
    >>> headers = {'content-type': 'application/json'}
    
    >>> r = requests.post(url, data=json.dumps(payload), headers=headers)
    

You might want to change the `headers` to

    
    
    headers = {'content-type': 'application/octet-stream'}
    response = requests.post( url, files=sample, params=params, verify=False,
                 headers = headers)
    

