Skip to content
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

"Non-BMP character" Unicode error #16

Closed
f-macfarlane95 opened this issue Mar 7, 2014 · 6 comments
Closed

"Non-BMP character" Unicode error #16

f-macfarlane95 opened this issue Mar 7, 2014 · 6 comments

Comments

@f-macfarlane95
Copy link

Hi all,
I know this is probably a really simple thing, but i'm relatively new to programming and looking for some help with an error i keep encountering.
This is the error here:

Traceback (most recent call last):
File "C:\Users\Fraser\Desktop\TwitterStream.py", line 19, in
print(item['text'] if 'text' in item else item)
File "C:\Python33\lib\idlelib\PyShell.py", line 1318, in write
return self.shell.write(s, self.tags)
UnicodeEncodeError: 'UCS-2' codec can't encode characters in position 118-118: Non-BMP character not supported in Tk

Any idea what would help with this?
thanks!

@th3o6a1d
Copy link

th3o6a1d commented Mar 7, 2014

Hi there,
Encoding has always been the bane of my existence as a new programmer myself. I need to do a little more reading, but basically, the tweet contains characters that your terminal ("print" command) doesn't understand without you telling it how to interpret them. For now, I would try:

encoded = string.encode("utf-8", errors='ignore')
print encoded

This will force all tweet characters into utf-8, although you may lose some emojis and fancy icons.
For a working demo of a script I wrote using TwitterAPI, checkout github.com/th3o6a1d/suicide_watch

th3o6a1d

@f-macfarlane95
Copy link
Author

cheers, i will try that and get back to you!

@th3o6a1d
Copy link

th3o6a1d commented Mar 7, 2014

Awesome... let me know if you need any help. Messing with the TwitterAPI was a fun person project a few months ago. Trying to figure out how I can use it going forward.

@f-macfarlane95
Copy link
Author

i tried what you suggested above and it gave this error message,

Traceback (most recent call last):
File "C:\Users\Fraser\Desktop\TwythonStream.py", line 28, in
encoded = Data.encode("utf-8", errors='ignore')
AttributeError: 'tuple' object has no attribute 'encode'

this was after importing codecs.py and having the class which defined the encode function available.

Is this something to do with the encode function not being relevant to the incoming text from the API?

@th3o6a1d
Copy link

th3o6a1d commented Mar 7, 2014

Whatever you're trying to code is the data type called "tuple". Data types refer to the way info is stored in memory. Other data types include "string", "integer", "boolean".

The encode operation works on string data types, so you need to make sure you're extracting the tweet text, loading it into a string variable, and encoding.

To learn more about data types, I recommend the Codecademy.com course on Python. It will save you a lot of time and frustration to go through the exercises.

On Mar 7, 2014, at 8:39 AM, f-macfarlane95 notifications@github.com wrote:

i tried what you suggested above and it gave this error message,

Traceback (most recent call last):
File "C:\Users\Fraser\Desktop\TwythonStream.py", line 28, in
encoded = Data.encode("utf-8", errors='ignore')
AttributeError: 'tuple' object has no attribute 'encode'

this was after importing codecs.py and having the class which defined the encode function available.

Is this something to do with the encode function not being relevant to the incoming text from the API?


Reply to this email directly or view it on GitHub.

@geduldig geduldig added question and removed question labels Mar 7, 2014
@f-macfarlane95
Copy link
Author

thanks very much for your help, i will do!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants