Skip to content

Instantly share code, notes, and snippets.

@michaelhelmick
Created May 13, 2012 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelhelmick/2690021 to your computer and use it in GitHub Desktop.
Save michaelhelmick/2690021 to your computer and use it in GitHub Desktop.
import requests
from requests.auth import OAuth1
url = 'https://upload.twitter.com/1/statuses/update_with_media.json'
auth = OAuth1(app_key, app_secret,
oauth_token, oauth_secret,
signature_type='auth_header')
data = {'status': 'Testing status with images'}
the_file = '/path/to/file/on/my/computer/image.jpg'
file_ = {'media': (the_file, open(the_file, 'rb'))}
print requests.post(url, data=data, files=file_, auth=auth)
# returns a <Response[401]>
'''
If I set data={} it returns a <Response[200]> and posts the status with just a link to the image
(https://twitter.com/#!/kevinkrpstomp/status/201767758894071811)
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment