title: How to base64 encode a picture for twitter in python?
body: <p>So I have been trying, (without luck) to base64 encode a image to upload to twitter with the Twython library. Iv'e done it the way I know how but it don't seem to work.</p>
  
  <pre><code>from twython import Twython
  import base64
  
  #keys
  APP_KEY = '*************'
  APP_SECRET = '**************'
  OAUTH_TOKEN = '**********************'
  OAUTH_TOKEN_SECRET = '*************************'
  #start twitter instance
  twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
  
  #encode image to bas64
  with open("image.jpeg", "rb") as imageF:
      st = base64.b64encode(imageF.read())
      #print to make sure its being encoded
      print st
  
  #update twitter banner
  twitter.update_profile_background_image(image=st)
  </code></pre>
  
  <p>The twitter docs don't help to much. <a href="https://dev.twitter.com/rest/reference/post/account/update_profile_banner" rel="nofollow">https://dev.twitter.com/rest/reference/post/account/update_profile_banner</a> 
  Nor does the Twython Docs. <a href="https://twython.readthedocs.org/en/latest/api.html" rel="nofollow">https://twython.readthedocs.org/en/latest/api.html</a> 
  Let me know how you would do it. Or if you have a better way.</p>
  
  <p>Thanks</p>