【发布时间】:2017-06-16 00:31:34
【问题描述】:
我一直在使用 Tweepy,当我执行 tweepy 的过滤器传递非 ascii 字符时出现错误。例如,使用以下命令,我得到以下错误:
我的代码:
auth = tweepy.OAuthHandler(apikey[0], apikey[1])
auth.set_access_token(apikey[2], apikey[3])
api = tweepy.API(auth)
sapi = tweepy.streaming.Stream(auth, CustomStreamListener())
sapi.filter(track=['eleições'])
我的错误:
Traceback (most recent call last):
File "./TwitterStreamingAPI.py", line 81, in <module>
sapi.filter(track=['eleições'])
File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 303, in filter
encoded_track = [s.encode(encoding) for s in track]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 4: ordinal not in range(128)
如果有人帮助我解决它,我会很高兴。
提前致谢,
蒂亚戈。
【问题讨论】:
-
你使用的是 Python3 还是 Python2?
-
我使用的是 Python 2.7.6
标签: python twitter utf-8 tweepy