Tweepy update status with media -UnicodeDecodeError: 'ascii' codec can't decode error

风流意气都作罢 提交于 2019-12-11 13:58:47

问题


Using Tweepy to update twitter post with photo.

Update with status alone works fine.

I am building my file name / path in Windows as follows:

path = 'C:/Users/foo/Documents/media/'
photoname = 'photo1.jpg'
filename = path + photoname

This prints out as a nicely formatted path and copied into Windows Explorer, opens the photo, so the path and photo name are correct.

However, when I execute with the filename in the update_with_media:

api.update_with_media(filename, status=tweet)

I get the following error message:

File "build/bdist.macosx-10.9-intel/egg/tweepy/api.py", line 98, in update_with_media
File "build/bdist.macosx-10.9-intel/egg/tweepy/api.py", line 747, in _pack_image
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

Any ideas on what is happening?

Thanks!


回答1:


Resolved this by updating to newer version of Tweepy. I had only recently installed Tweepy but somehow got an older version.

I was using v 2.3 and did pip install --upgrade tweepy which updated to v 3.3

The underlying issue appeared to be that Twitter had since deprecated their update status with media process so the newer version of Tweepy included those changes.

However very nice to see that Tweepy keeps their functionality the same. The function 'api.update_with_media(filename, status=tweet)' is in new version too and Tweepy simply deals with Twitter API changes 'under the hood'.



来源:https://stackoverflow.com/questions/31851585/tweepy-update-status-with-media-unicodedecodeerror-ascii-codec-cant-decode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!