trstringer / redditwatcher

:radio: Reddit streaming CLI
19 stars 0 forks source link

UnicodeEncodeError #2

Closed ekt1701 closed 7 years ago

ekt1701 commented 7 years ago

From time to time I get the following error:

Traceback (most recent call last):
  File "app.py", line 53, in <module>
    main()
  File "app.py", line 20, in main
    display_submission(submission)
  File "app.py", line 48, in display_submission
    submission.title
UnicodeEncodeError: 'ascii' codec can't encode character u'\u201c' in position 10: ordinal not in range(128)

Otherwise, this works great!

trstringer commented 7 years ago

Thank you for opening the issue! I'll dig into this and see what I can figure out.

Quick question, when you called redditwatcher, which subreddits did you pass in as args? If you remember, of course. Thanks! 👍 😄

ekt1701 commented 7 years ago

Yes it was the Python subreddit. Here is where it broke:

/r/Python [4/26 3:35 P] https://redd.it/67rln8
    Pyparsing help.
/r/Python [4/26 6:19 P] https://redd.it/67si44
    What's this sub about?
Traceback (most recent call last):
  File "app.py", line 56, in <module>
    main()
  File "app.py", line 23, in main
    display_submission(submission)
  File "app.py", line 51, in display_submission
    submission.title
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2014' in position 44: ordinal not in range(128)

Here is the title that caused the error: 100 Scripts in 30 Days challenge: Script 22 — Learning Some Python Basic Data Structures (Lists, Tuples, Numpy Arrays)

I get this error with Python 2.7

trstringer commented 7 years ago

Ah, ok, I should've specified originally. This required python3! I think the unicode issues might be stemming from python2.

I think you probably installed this prior to me changing around the installation process 😢

My recommendation would be to:

  1. uninstall pip uninstall . in the redditwatcher directory
  2. fetch updates git fetch origin
  3. merge those updates git merge origin/master
  4. do the new installation ./install

Hopefully that helps! Closing this for now, let me know if any other issues arise!

ekt1701 commented 7 years ago

Actually, I didn't use the installation process, I'm running the app.py from the terminal and hard coded the subreddits.

BTW, I found a workaround for Python 2.7 I added the following lines and no more Unicode errors. :)

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

FYI, Also, I had to use these lines, otherwise, I was getting a key error.

reddit = praw.Reddit(client_id='REDDITWATCHER_CLIENTID',
                         client_secret='REDDITWATCHER_CLIENTSECRET',
                         user_agent='redditwatcher')