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

Fix UnicodeDecodeError during installation #86

Merged
merged 2 commits into from
May 23, 2018
Merged

Conversation

elvisyjlin
Copy link
Contributor

I encountered the following error when installing gallery-dl using Python 3.5.2 on Ubuntu 16.04 LTS.

Installation command

python3 setup.py install

Encountered error

Traceback (most recent call last):
  File "setup.py", line 21, in <module>
    exec(read("gallery_dl/version.py"))
  File "setup.py", line 17, in read
    return open(os.path.join(os.path.dirname(__file__), fname)).read()
  File "/usr/lib/python3.5/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 53: ordinal not in range(128)

In the file gallery_dl/version.py, there is a non-ascii character in name Mike Fährmann.
So setup.py failed to read the version with default encoding ascii and raised the exception.

Original read() in setup.py

def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname)).read()

I revised read() into

def read(fname):
    import codecs
    return codecs.open(os.path.join(os.path.dirname(__file__), fname), 'r', 'utf-8').read()

And gallery-dl was installed successfully.

@mikf
Copy link
Owner

mikf commented May 23, 2018

Thanks for your contribution.

I think it would be better to just use the encoding keyword argument for open() instead of importing the codecs module. So something like this:

return open(os.path.join(os.path.dirname(__file__), fname), encoding="utf-8").read()

(also use double quotes " if possible)

It's weird that your Python is using ASCII as default encoding. It should be UTF-8 (or the selected codepage on Windows).

@iamleot
Copy link
Contributor

iamleot commented May 23, 2018 via email

@mikf mikf merged commit aab2391 into mikf:master May 23, 2018
@elvisyjlin
Copy link
Contributor Author

Hi Mike,
You're right. Adding the keyword encoding works for me. I'm just used to using codecs to deal with encoding problems. Thank you!

Thanks iamleot for your information about the environment variable LC_CTYPE.

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

Successfully merging this pull request may close these issues.

3 participants