title: Upload image to facebook using the Python API
body: <p>I have searched the web far and wide for a still working example of uploading a photo to facebook through the Python API (<a href="https://github.com/pythonforfacebook/facebook-sdk" rel="nofollow" title="Python for Facebook">Python for Facebook</a>). Questions like this have been asked on stackoverflow before but non of the answers I have found work anymore.</p>
  
  <p>What I got working is:</p>
  
  <pre><code>import facebook as fb
  
  cfg = {
      "page_id"      : "my_page_id",
      "access_token" : "my_access_token"
      }
  
  api = get_api(cfg)
  msg = "Hello world!"
  status = api.put_wall_post(msg) 
  </code></pre>
  
  <p>where I have defined the <em>get_api(cfg)</em> function as this</p>
  
  <pre><code>graph = fb.GraphAPI(cfg['access_token'], version='2.2')
  
  # Get page token to post as the page. You can skip
  # the following if you want to post as yourself.
  resp = graph.get_object('me/accounts')
  page_access_token = None
  for page in resp['data']:
      if page['id'] == cfg['page_id']:
          page_access_token = page['access_token']
  graph = fb.GraphAPI(page_access_token)
  return graph
  </code></pre>
  
  <p>And this does indeed post a <em>message</em> to my <em>page</em>.
  However, if I instead want to upload an image everything goes wrong. </p>
  
  <pre><code># Upload a profile photo for a Page.
  api.put_photo(image=open("path_to/my_image.jpg",'rb').read(), message='Here's my image')
  </code></pre>
  
  <p>I get the dreaded <em>GraphAPIError: (#324) Requires upload file</em> for which non of the solutions on stackoverflow works for me.
  If I instead issue the following command</p>
  
  <pre><code>api.put_photo(image=open("path_to/my_image.jpg",'rb').read(), album_path=cfg['page_id'] + "/picture")
  </code></pre>
  
  <p>I get <em>GraphAPIError: (#1) Could not fetch picture</em> for which I haven't been able to find a solution either. </p>
  
  <p>Could someone out there please point me in the right direction of provide me with a currently working example? It would be greatly appreciated, thanks ! </p>