我在尝试执行程序时遇到此错误。请注意,我使用的是Python Twitter工具,并且不会发布我的完整代码,因为它包含与我的Twitter相关的信息。
Traceback (most recent call last):
File "E:\Programming\Code\Twitter App\Twitter.py", line 57, in <module>
Main()
File "E:\Programming\Code\Twitter App\Twitter.py", line 32, in Main
Timeline()
File "E:\Programming\Code\Twitter App\Twitter.py", line 53, in Timeline
print ("(%s) @%s %s" % (status["created_at"], status["user"]["screen_name"], status["text"]))
File "C:\Python34\lib\encodings\cp437.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f62d' in position 55: character maps to <undefined>
我的代码如下:
while True:
#-----------------------------------------------------------------------
# request my home timeline
# twitter API docs: https://dev.twitter.com/docs/api/1/get/statuses/home_timeline
#-----------------------------------------------------------------------
statuses = twitter.statuses.home_timeline(count = 50)
#-----------------------------------------------------------------------
# loop through each of my statuses, and print its content
#-----------------------------------------------------------------------
for status in statuses:
print ("(%s) @%s %s" % (status["created_at"], status["user"]["screen_name"], status["text"]))
为什么我收到此错误,我感到非常困惑。如果您需要更多代码,请提出要求,但我会隐藏个人信息。
编辑: 在显示任何推文之前,我似乎偶尔也会收到此错误。
Traceback (most recent call last):
File "E:\Programming\Code\Twitter App\Twitter.py", line 57, in <module>
Main()
File "E:\Programming\Code\Twitter App\Twitter.py", line 32, in Main
Timeline()
File "E:\Programming\Code\Twitter App\Twitter.py", line 53, in Timeline
print ("(%s) @%s %s" % (status["created_at"], status["user"]["screen_name"], status["text"]))
File "C:\Python34\lib\encodings\cp437.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 66-70: character maps to <undefined>