python - Twython - How to update status with media url -


in app, let users post twitter. let them update status media.

in twython.py see method update_status_with_media reads image filesystem , uploads twitter. images not in filesystem on s3 bucket.

how make work s3 bucket urls?

passing url in file_ variable, fails on io error, no such file or directory.

passing stringio fails on unicodedecode error.

passing urllib.urlopen(url).read() gives file() argument 1 must encoded string without null bytes, not str.

i tried using post method , got 403 forbidden twitter api, error creating status.

just solved it

bah, got work, finally! maybe else save few hours cost me.

twitter = twython(         app_key=settings.twitter_consumer_key, app_secret=settings.twitter_consumer_secret,         oauth_token=token.token, oauth_token_secret=token.secret     ) img = requests.get(url=image_obj.url).content tweet = twitter.post('statuses/update_with_media',                                  params={'status': msg},                                  files={'media': (image_obj.url,                                                   bytesio(img))}) 

glad see found answer! there's similar problem handled in repo issue - basically, can following stringio , passing directly twitter.post did:

from stringio import stringio twython import twython  t = twython(...) img = open('img_url').read() t.post('/statuses/update_with_media', params = {'status': 'testing new status'}, files = {     'media': stringio(img)     # 'media': ('orthisifyouwanttonamethefile.lol', stringio(img)) }) 

this isn't direct answer question, i'm not expecting vote or anything, figured it's seemingly useful people , related i'd drop note.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -