rhiever / reddit-analysis

A Python script that parses post titles, self-texts, and comments on reddit and makes word clouds out of the word frequencies.
286 stars 63 forks source link

UnicodeEncodeError: 'ascii' codec can't encode character #54

Open catlover99 opened 8 years ago

catlover99 commented 8 years ago

When using word_freqs [username] [/u/username] --verbose I ran into this error with out_text

Traceback (most recent call last): File "C:\Python27\Scripts\word_freqs-script.py", line 9, in <module> load_entry_point('redditanalysis==1.0.4', 'console_scripts', 'word_freqs')() File "c:\python27\lib\site-packages\redditanalysis\__init__.py", line 400, in main out_text = str("{0}:{1}\n".format(word, popular_words[word])) UnicodeEncodeError: 'ascii' codec can't encode character u'\u0296' in position 0: ordinal not in range(128)

Encoding late will solve this issue and both instances of out_text on lines 404 and 419 in

\lib\site-packages\redditanalysis\__init\.py

can be changed from

out_text = str("{0}:{1}\n".format(word, popular_words[word]))

to

out_text = str("{0}:{1}\n".format(word.encode('utf-8'), popular_words[word]))