0

I have the following code:

photo = open(os.path.join("images", localFileName), 'rb')
tweetThis = "status"
twitter.update_status_with_media(status=tweetThis, media=photo)

Here is the traceback:

    twitter.update_status_with_media(status=status, media=photo)
  File "/usr/local/lib/python2.7/site-packages/twython/endpoints.py", line 107, in update_status_with_media
    return self.post('statuses/update_with_media', params=params)
  File "/usr/local/lib/python2.7/site-packages/twython/api.py", line 234, in post
    return self.request(endpoint, 'POST', params=params, version=version)
  File "/usr/local/lib/python2.7/site-packages/twython/api.py", line 224, in request
    content = self._request(url, method=method, params=params, api_call=url)
  File "/usr/local/lib/python2.7/site-packages/twython/api.py", line 194, in _request
    retry_after=response.headers.get('retry-after'))
twython.exceptions.TwythonError: Twitter API returned a 403 (Forbidden), Status creation failed: Tweet creation failed.

I have tested twitter.update_status(status='TEST') which works correctly meaning I have the correct credentials and permissions. What's wrong with the media version?

Morki
  • 215
  • 1
  • 3
  • 11

1 Answers1

1

Try changing os.path.join("images", localFileName) to just /path/to/file. Not completely sure, but this is the only likely thing that is going wrong. Also, don't set your variable for your status to be status, it shadows the twython syntax: twython.twitter.update_status_with_media(status, media)

Here is an example:

from twython import Twython
from time import strftime

CONSUMER_KEY = '***'
CONSUMER_SECRET = '***'
ACCESS_KEY = '***'
ACCESS_SECRET = '***'

#load your twitter credentials
twyapi = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)
photo = open('/Users/aj8uppal/Desktop/images.jpg', 'rb')
twyapi.update_status_with_media(status='I love python!', media=photo)
A.J. Uppal
  • 19,117
  • 6
  • 45
  • 76