title: "Bad Gateway" error using Python requests module with multipart encoded file POST
body: <p>I am getting the error message "Bad Gateway
  <p>The proxy server received an invalid
  response from an upstream server" with the following code:</p>
  
  <pre><code>import requests
  
  url = "https://apis.company.com/v3/media"
  attachments = 'media': ('x.mp3', open('x.mp3', 'r'))}
  headers = {'content-type': "multipart/form-data",'cache-control': "no-cache" 
            'Authorization':"Bearer zzz" }
  response = requests.post(url, files=attachments, headers = headers)
  print response.text
  </code></pre>
  
  <p>I'm following the example in the requests Quickstart documentation, where it says "You can also pass a list of tuples to the data argument": <a href="http://docs.python-requests.org/en/master/user/quickstart/#post-a-multipart-encoded-file" rel="nofollow noreferrer">http://docs.python-requests.org/en/master/user/quickstart/#post-a-multipart-encoded-file</a></p>
  
  <p>What is causing this error and how can I fix it? </p>