New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UnicodeEncodeError: 'charmap' codec can't encode character u'\u2026' in position 139: character maps to <undefined> #1
Comments
run steps:
|
encode the text when printing print(tweet.text.encode("utf-8")) |
@ravindukaluarachchi suggested good. It works fine. public_tweets = api.home_timeline()
for tweet in public_tweets:
# print(tweet.text);
print ((tweet.text).encode('utf8')) |
UnicodeEncodeError: 'UCS-2' codec can't encode characters in position 44-44: Non-BMP character not supported in Tk Getting this error |
Can you check https://stackoverflow.com/questions/32442608/ucs-2-codec-cant-encode-characters-in-position-1050-1050 if this is useful. |
what if the print statement hold jason not a text? it didn't work like this print(status._json.encode("utf-8")) |
Then simply dont print the json output (the returned tweets) to the console and avoid that as much as possible. |
Well the problem is not with python actually , I was getting a similar I did a simple fix in windows there is a way you can set the defaulting encoding to utf-8 like I did but this feature is only available as a beta in win 10 but it resolved the error for me so the way to test if python renders the problematic character in python is to just enter interactive mode in python and just print('xxxxx') my bet is it will another thing is I am using vs code as my ide which sets the encoding to utf-8 for python by default Hope that helps |
Thanks.....for kick-ass solution dude |
any1 can help to finish it |
Please hep me to solve this ' File "C:\ProgramData\Anaconda3\lib\encodings\cp1252.py", line 19, in encode', Thanks |
import io |
thank u so much I was getting this problem from 2 days I was not able to solve it but after trying your solution it worked thanks a lot |
I can't replay this error but I realized this error might be happened only on Windows. so I referred other same error llSourcell/twitter_sentiment_challenge#1
|
same problem |
open('test.txt', 'w+', encoding="utf-8") |
with open('example.txt', '(r/ w / a)', encoding='utf-8') as f: |
Since Python 3.7 you can change the encoding of standard streams with reconfigure() confirm whether encoding has changed from cp1252 to utf-8 |
C:\LEARN PYTHON\sirajology\twitter_sentiment_challenge>python demo.py
Traceback (most recent call last):
File "demo.py", line 27, in
print(tweet.text)
File "C:\Python27\lib\encodings\cp852.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u2026' in position 139: character maps to
The text was updated successfully, but these errors were encountered: