title: Python Request: Post Images on Facebook using Multipart/form-data
body: <p>I'm using the facebook API to post images on a page, I can post image from web using this :</p>
  
  <pre><code>import requests
  
  data = 'url=' + url + '&amp;caption=' + caption + '&amp;access_token=' + token
  status = requests.post('https://graph.facebook.com/v2.7/PAGE_ID/photos',
                         data=data)
  print status
  </code></pre>
  
  <p>But when I want to post a local image (using multipart/form-data) i get the error : <code>ValueError: Data must not be a string.</code>  </p>
  
  <p>I was using this code:</p>
  
  <pre><code>data = 'caption=' + caption + '&amp;access_token=' + token
  files = {
      'file': open(IMG_PATH, 'rb')
      }
  
  status = requests.post('https://graph.facebook.com/v2.7/PAGE_ID/photos',
                         data=data, files=files)
  print status
  </code></pre>
  
  <p>I read (<a href="https://stackoverflow.com/questions/19439961/python-requests-post-json-and-file-in-single-request/19440099#19440099">Python Requests: Post JSON and file in single request</a>) that maybe it's not possible to send both data and files in a multipart encoded file so I updated my code :</p>
  
  <pre><code>data = 'caption=' + caption + '&amp;access_token=' + token
  files = {
      'data': data,
      'file': open(IMG_PATH, 'rb')
      }
  
  status = requests.post('https://graph.facebook.com/v2.7/PAGE_ID/photos',
                         files=files)
  print status
  </code></pre>
  
  <p>But that doesn't seem to work, I get the same error as above.<br>
  Do you guys know why it's not working, and maybe a way to fix this.</p>