title: Python Requests: Post JSON and file in single request
body: <p>I need to do a API call to upload a file along with a JSON string with details about the file.</p>
  
  <p>I am trying to use the python requests lib to do this:</p>
  
  <pre><code>import requests
  
  info = {
      'var1' : 'this',
      'var2'  : 'that',
  }
  
  data = json.dumps({
      'token' : auth_token,
      'info'  : info,
  })
  
  headers = {'Content-type': 'multipart/form-data'}
  
  files = {'document': open('file_name.pdf', 'rb')}
  
  r = requests.post(url, files=files, data=data, headers=headers)
  </code></pre>
  
  <p>This throws the following error:</p>
  
  <pre><code>    raise ValueError("Data must not be a string.")
   ValueError: Data must not be a string
  </code></pre>
  
  <p>If I remove the 'files' from the request, it works.<br>
  If I remove the 'data' from the request, it works.<br>
  If I do not encode data as JSON it works.</p>
  
  <p>For this reason I think the error is to do with sending JSON data and files in the same request.</p>
  
  <p>Any ideas on how to get this working?</p>