python-3.x - Tweepy 编码错误:UnicodeEncodeError:“UCS-2”编解码器无法对位置 14-14 中的字符进行编码:Tk 中不支持非 BMP 字符
问题描述
我在 StackOverflow 上阅读了其他一些答案,并且我(大致)知道问题所在:Tweepy 和 Python 在转换某些字符(很可能是比特币)时遇到了一些困难,我看到了一些解决方案,但我太编程挑战应用它们(你可以从我的用户名中猜到)。
将不胜感激任何帮助解决这个问题。使用最新的 Python 3.x。
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import json
#consumer key, consumer secret, access token, access secret.
ckey=""
csecret="" #Removed for privacy
atoken="" #Removed for privacy
asecret="" #Removed for privacy
class listener(StreamListener):
def on_data(self, data):
all_data = json.loads(data)
tweet = all_data["text"]
print((tweet))
return True
def on_error(self, status):
print(status)
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, listener())
twitterStream.filter(track=["car"])
解决方案
我在网上找到了答案。
您添加一个 ascii 包装器:
推文 = ascii(all_data["text"])
推荐阅读
- javascript - Javascript setInterval,如何返回一个值?
- javascript - 使用 .equals 的 Dexie.js 查询不适用于 localStorage
- amazon-s3 - 使用和不使用 --dryrun 选项运行 s3 同步之间的时间差
- java - 带引用链的 JPA 复合主键
- css - 在使用滚动捕捉时实现页脚
- visual-studio-code - VScode自定义集成终端不显示输出中的所有路径
- javascript - 如何在 vuetify 的 v-combobox 中使用 no-data-text 道具?
- javascript - 麦克风在应用程序中被禁用/不工作(从网站转换)
- jquery - DataTables - 我不想一次加载所有数据?
- c# - C# 填充列表
使用来自另一个类的字符串和默认构造函数