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

UnicodeEncodeError #39

Open
nmandal opened this issue Apr 13, 2017 · 23 comments
Open

UnicodeEncodeError #39

nmandal opened this issue Apr 13, 2017 · 23 comments

Comments

@nmandal
Copy link

nmandal commented Apr 13, 2017

$ python export_saved.py
Traceback (most recent call last):
File "export_saved.py", line 305, in
main()
File "export_saved.py", line 299, in main
save_saved(reddit)
File "export_saved.py", line 267, in save_saved
process(reddit, seq, "export-saved", "Reddit - Saved")
File "export_saved.py", line 247, in process
csv_rows = get_csv_rows(reddit, seq)
File "export_saved.py", line 194, in get_csv_rows
logging.debug('title: {}'.format(title))
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2014' in position 90: ordinal not in range(128)

@netfortius
Copy link

netfortius commented Apr 16, 2017

Similar issue - but with the " character (u201c) found somewhere:

UnicodeEncodeError: 'ascii' codec can't encode character u'\u201c' in position 17: ordinal not in range(128)

Edit 5/2/2017: pulled and tested the latest version - same issue, apparently somewhere else:

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 83: ordinal not in range(128)

@admish
Copy link

admish commented May 7, 2017

Use Python 3 and this error will clear up.

If you have multiple versions of python installed use python3 export_saved.py to run. You might also need to install praw as well with pip3 install praw.

@rachmadaniHaryono
Copy link
Collaborator

rachmadaniHaryono commented May 7, 2017

Thank you @admish for commenting here. Did you use the recent commit with #38?

This could mean this issue can be closed alongside with already closed issue #37 without waiting response @netfortius and @nmandal.

@admish
Copy link

admish commented May 7, 2017

@rachmadaniHaryono I just installed this today so have only ever used the latest commit. Running Python 2.7.12 and Python 3.4.2 on macOS 10.12.4. Python3 with praw 4.5 ran flawlessly while Python 2.7 gave the following error:

Version 4.4.0 of praw is outdated. Version 4.5.0 was released 7 days ago.
Traceback (most recent call last):
  File "export_saved.py", line 321, in <module>
    main()
  File "export_saved.py", line 315, in main
    save_saved(reddit)
  File "export_saved.py", line 283, in save_saved
    process(reddit, seq, "export-saved", "Reddit - Saved")
  File "export_saved.py", line 265, in process
    write_csv(csv_rows, file_name + ".csv")
  File "export_saved.py", line 242, in write_csv
    csvwriter.writerow(row)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2018' in position 10: ordinal not in range(128)

@rachmadaniHaryono
Copy link
Collaborator

rachmadaniHaryono commented May 7, 2017

Did you come the repo or just download the export_saved file? If you clone the repo can you check which commit you are now?

I will add program version flag so people can easily recognize the version later.

Also python2.7 is actually not officially supported (and we haven't wrote any python requirement in readme, sorry for that).

But I will patch this python2.7 if the latest pr can't fix it.

  • add program version
  • add python requirement on Readme

@admish
Copy link

admish commented May 7, 2017

Yes, I cloned the repo.

By default, OS X comes with Python 2.7. Following the instructions in the README on Macs without knowing this, the script won't work. To anyone else reading this you can change the default version by editing your ~/.bash_profile to include the line alias python='python3' then relaunch your terminal.

If this would help, here is the latest entry in the log.

:~/Workspace/export-saved-reddit$ git log
commit 9841839e273bc8675bc7bb96112650957131fb6c
Merge: 8277d77 5d2ca4b
Author: Christopher Su <[email protected]>
Date:   Wed Apr 26 19:51:43 2017 -0700

    Merge pull request #38 from rachmadaniHaryono/feature/fix-csv-type-error

    fix: usr: TypeError when writing csv field

@rachmadaniHaryono
Copy link
Collaborator

rachmadaniHaryono commented May 7, 2017

@admish can you check once again on python2.7 version?

e: checkout the branch on the pr and run it once again.

e2: actually on requirement it is already recommended to use python3

Requirements

  • Python 3.x

i recommend @netfortius and @nmandal can use python3

the next version i may add an error if python2 is used.

@admish
Copy link

admish commented May 8, 2017

Same error.

@rachmadaniHaryono
Copy link
Collaborator

on the same line? 254 or 256?

@admish
Copy link

admish commented May 8, 2017

Version 4.4.0 of praw is outdated. Version 4.5.0 was released 7 days ago.
Traceback (most recent call last):
  File "export_saved.py", line 329, in <module>
    main()
  File "export_saved.py", line 323, in main
    save_saved(reddit)
  File "export_saved.py", line 287, in save_saved
    process(reddit, seq, "export-saved", "Reddit - Saved")
  File "export_saved.py", line 269, in process
    write_csv(csv_rows, file_name + ".csv")
  File "export_saved.py", line 246, in write_csv
    csvwriter.writerow(row)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u201d' in position 68: ordinal not in range(128)

@rachmadaniHaryono
Copy link
Collaborator

@admish can you try it once again?

the recent code c8cca7e

if there is any error there should be only on line number 254, 256, 263, or 265

@admish
Copy link

admish commented May 10, 2017

Still the same error.

Version 4.4.0 of praw is outdated. Version 4.5.1 was released 2 days ago.
Traceback (most recent call last):
  File "export_saved.py", line 329, in <module>
    main()
  File "export_saved.py", line 323, in main
    save_saved(reddit)
  File "export_saved.py", line 287, in save_saved
    process(reddit, seq, "export-saved", "Reddit - Saved")
  File "export_saved.py", line 269, in process
    write_csv(csv_rows, file_name + ".csv")
  File "export_saved.py", line 246, in write_csv
    csvwriter.writerow(row)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u201d' in position 68: ordinal not in range(128)

The git pull was successful and this was on the latest merge.

## $ git log
commit 64a37f64037c3eec623ba16de962c7a5da35f1d5
Merge: 9841839 9d4d027
Author: rachmadani haryono <[email protected]>
Date:   Mon May 8 06:51:03 2017 +0800

    Merge pull request #42 from rachmadaniHaryono/feature/add-program-version

    chg: dev: add program version.

@rachmadaniHaryono
Copy link
Collaborator

yeah, but that isn't the pull request branch.

add my fork and checkout the branch.

git remote add rachmadaniHaryono https://github.com/rachmadaniHaryono/export-saved-reddit
git checkout rachmadaniHaryono/feature/fix-py27-writerow

this should be the result from git show

commit c8cca7e5f2734d9afd41a05b75f470aafee0f1ce
Author: rachmadaniHaryono <[email protected]>
Date:   Thu May 11 03:32:14 2017 +0800

@admish
Copy link

admish commented May 10, 2017

Traceback (most recent call last):
  File "export_saved.py", line 339, in <module>
    main()
  File "export_saved.py", line 333, in main
    save_saved(reddit)
  File "export_saved.py", line 297, in save_saved
    process(reddit, seq, "export-saved", "Reddit - Saved")
  File "export_saved.py", line 279, in process
    write_csv(csv_rows, file_name + ".csv")
  File "export_saved.py", line 256, in write_csv
    csvwriter.writerow(row.encode('utf8', 'ignore'))
AttributeError: 'list' object has no attribute 'encode'
 $ git log
commit c8cca7e5f2734d9afd41a05b75f470aafee0f1ce
Author: rachmadaniHaryono <[email protected]>
Date:   Thu May 11 03:32:14 2017 +0800

    chg: dev: fix variable typo

@rachmadaniHaryono
Copy link
Collaborator

@admish dbe00b0

@admish
Copy link

admish commented May 10, 2017

Traceback (most recent call last):
  File "export_saved.py", line 339, in <module>
    main()
  File "export_saved.py", line 333, in main
    save_saved(reddit)
  File "export_saved.py", line 297, in save_saved
    process(reddit, seq, "export-saved", "Reddit - Saved")
  File "export_saved.py", line 279, in process
    write_csv(csv_rows, file_name + ".csv")
  File "export_saved.py", line 256, in write_csv
    csvwriter.writerow([x.encode('utf8', 'ignore') for x in row])
AttributeError: 'int' object has no attribute 'encode'

@admish
Copy link

admish commented May 10, 2017

Would you like me to setup an OS X VM for you?

@rachmadaniHaryono
Copy link
Collaborator

rachmadaniHaryono commented May 10, 2017

yes, if possible

e:@admish fb3a4b5

@admish
Copy link

admish commented May 10, 2017

Setting up a new one now, but also about to leave work so give me a couple hours. In the meantime email me a public key that I can add into the authorized_keys file, and when I have the login info setup I'll share it so you can login.

@netfortius
Copy link

netfortius commented Jul 17, 2017

Issue is back, at least on OSX. Unicode error, regardless of version of python or praw used. Tried two different machines, one with python2 & praw 4.5.1, and one with python3 and praw 5.0.1. Then upgraded praw on the python2 machine, to cover that combo - consistent error across all: "can't encode character '\xe0' in position 66: ordinal not in range (128)"

lukepayne added a commit to lukepayne/export-saved-reddit that referenced this issue Aug 28, 2017
Fix for unicode errors and conversion process

ref: csu#39
@lukepayne
Copy link
Contributor

It looks like this issue wasn't resolved, so I have opened a PR.
@csu could you please take a look / merge if appropriate? Thanks!

@rachmadaniHaryono
Copy link
Collaborator

Iirc the 3 PRs are actually for this issue, yet nobody mention if the issue is already fixed by one of these

@lukepayne
Copy link
Contributor

You're right, it looks like there are 2 other PR requests that are in various states of completeness. It would be good to have a fix merged in for this issue so that others don't have to run into it.

bmikolaj added a commit to bmikolaj/export-saved-reddit that referenced this issue Sep 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants