schollz / twittermatic

7 stars 3 forks source link

Need to catch encoding errors somehow #8

Closed schollz closed 9 years ago

schollz commented 9 years ago

I got this error when saving Handler information for @RelatableDad on twitter:

Traceback (most recent call last):
  File "C:\Users\ZNS\Desktop\twittermatic\tweetgrabber.py", line 11, in getTweets
    bot.collectTweets(handle)
  File "C:\Users\ZNS\Desktop\twittermatic\lib.py", line 303, in collectTweets
    self.saveTwitterHandle(twitterhandle)
  File "C:\Users\ZNS\Desktop\twittermatic\lib.py", line 284, in saveTwitterHandle
    print(user)
  File "C:\Program Files (x86)\Python 3.5\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 '\u2026' in position 38: character maps to <undefined>

It looks like this can be solved by using .encode("utf-8"), so that will probably be necessary when collecting information.

schollz commented 9 years ago

Okay, for objects that are going to be sent to databases I've included a .encode('utf-8') which seemed to fix the problem.