- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 tweepy,在屏幕上打印推文消息时出现此错误 (Windows)。
#!/usr/bin/env python
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import json
#consumer key, consumer secret, access token, access secret.
ckey = 'xyz'
csecret = 'xyz'
atoken = 'xyz'
asecret = 'xyz'
class Listener(StreamListener):
def on_data(self, data):
print json.loads(data)['text']
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=['#hash1', '#hash2'], languages=['en'])
> Traceback (most recent call last): File
> "C:....twitterSentiment.py",
> line 34, in <module>
> twitterStream.filter(track=['#hash1', '#hash2'], languages=['en']) File
> line 430, in filter
> self._start(async) File "C:......streaming.py",
> line 346, in _start
> self._run() File "C:.....streaming.py",
> line 286, in _run
> raise exception UnicodeEncodeError: 'charmap' codec can't encode characters in position 108-111: character maps to <undefined>
这是Windows不支持所有字符造成的。有解决办法吗?
最佳答案
您收到此错误,因为它无法打印 tweet.text
的 unicode
部分。将其编码为 utf-8
(unicode)。
def on_data(self, data):
print json.loads(data)['text'].encode('utf-8')
return True
关于python - 'charmap' 编解码器无法编码字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32240013/
我正在使用 tweepy,在屏幕上打印推文消息时出现此错误 (Windows)。 #!/usr/bin/env python from tweepy import Stream from tweepy
我正在为我的项目使用 tinymce 编辑器。我想添加更多特殊字符(例如卢比符号 (₹))。但是我没有找到任何解决方案。 我的代码是 tinymce.init({ "selec
Python 在使用 wolfram alpha api 时抛出这个: Traceback (most recent call last): File "c:\Python27\lib\threa
我已经读过UnicodeDecodeError: 'charmap' codec can't decode byte X in position Y: character maps to .虽然错误
Python 在使用 wolfram alpha api 时抛出这个: Traceback (most recent call last): File "c:\Python27\lib\threa
我正在尝试抓取一个网站,但它给了我一个错误。 我正在使用以下代码: import urllib.request from bs4 import BeautifulSoup get = urllib.r
我一直在摆弄 python geopy,并尝试了文档中给出的基本命令。但我得到了 UnicodeEncodeError 尝试 raw 时命令(将查询地理定位到地址和坐标) print(location
使用 pandas 并每次使用“特殊”字符,例如:é出现它会抛出编码错误。这是我的代码: import pandas as pd df = pd.read_csv(r'movies analysis\
首先,如果之前有人问过这个问题,我深表歉意。我仍然非常熟悉编码,我不完全确定如果它就在我面前,我会寻找正确的答案,因此我给在此处发帖寻求帮助! 几年前,我涉足 cocos2d 一段时间,发现有一种非常
我已经阅读了我能找到的所有帖子,但我的情况似乎很独特。我对 Python 完全陌生,所以这可能是基础的。我收到以下错误: UnicodeDecodeError: 'charmap' codec can
我在 Windows CMD 窗口中运行时编写的 Python 脚本遇到了问题,并将问题的本质归结为以下 SSCCE : Python 脚本 (x.py) import sys in_file = o
我连接到 MySQL 并检索包含“Ö”、“ğ”、“Ş”等的用户名。它适用于 MySQL 或 PHP,但在 Python 2.6.8 中,会发生错误。这是我的代码: #C:\Python27\Lib\e
在任何人就这个被问了十亿次的问题向我吐槽之前,请注意我已经在许多线程中尝试了几个答案,但似乎没有一个能正确解决我的问题。 import json def parse(fn): results
我正在使用 Python 脚本打开 .csv 文件并将数据导入数据库。有几个导致错误的拉丁字符,所以我尝试用 UTF-8 对它们进行编码,并使用 errors='replace' 规范将那些麻烦的字符
我尝试运行以下 python 代码(安装了 Python 3.4.7 + scipy;安装了 MikTeX 2.9.4476;Windows 7) from matplotlib import pyp
我正在尝试使用 Anaconda 3.6 在 Windows 计算机上安装 Mayavi。 不幸的是,我收到一个我不明白的错误。我仍在探索 Python。 我已经在互联网上查看过其他类似的问题,但找不
我正在尝试使用 python 库进行数据分析,我面临的问题是这个异常 UnicodeDecodeError was unhandled by user code Message: 'charmap'
我想做搜索引擎,我在一些网络上学习教程。我想测试解析 html from bs4 import BeautifulSoup def parse_html(filename): """Extra
我正在关注 Justin Seitz 的书“Black Hat Python”。在本章中,我们将编写一个使用 GitHub 进行命令和控制并使用 github3.py 与 GitHub 交互的特洛伊木
这是一个 Django 项目。在本地 virtualenv 中运行 pip install -r requirements.txt 时遇到错误。 Collecting https://github.c
我是一名优秀的程序员,十分优秀!