question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnicodeDecodeError in python2

See original GitHub issue

googleimagesdownload -k ‘สวัสดีครับ’ -l 5

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/bin/googleimagesdownload", line 10, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/google_images_download/google_images_download.py", line 998, in main
    paths,errors = response.download(arguments)  #wrapping response in a variable just for consistency
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/google_images_download/google_images_download.py", line 825, in download
    paths, errors = self.download_executor(arguments)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/google_images_download/google_images_download.py", line 922, in download_executor
    print(iteration.encode('raw_unicode_escape').decode('utf-8'))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 29: ordinal not in range(128)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:6

github_iconTop GitHub Comments

5reactions
jose-tcommented, Jul 15, 2019

Same issue in python3.7.

A workaround is to replace non-ascii characters by their unicode representation.

Python 3:

def transliterate(string):
    """Transliterates string into his closest representation.
    Ex: 1. àé => ae,
        2. สวัสดีครับ => swasdiikhrab.
    :param string: string
    :return: closest string.
    """
    from unidecode import unidecode

    if not isinstance(string, bytes):
        string = u''.join(string)

    return unidecode(string)

Python 2:

Replace if not isinstance(string, bytes): by if not isinstance(string, unicode):

1reaction
chzhccommented, Jul 23, 2019

It’s a bug while trying to print the exactly name in the utf-8 encoding. if you were using python3, you can just git clone the project and remove the decode in google_images_download/google_images_download.py like this: print(iteration.encode('raw_unicode_escape').decode('utf-8'))
into print(iteration.encode('raw_unicode_escape')) then uninstall the origin one and python setup.py install the modified one. Althought it print bad on screen but it works fine. Using python2 will have another problem… ps. still dont know why the example in website using Chinese that pass but another language decode have problem …

Read more comments on GitHub >

github_iconTop Results From Across the Web

UnicodeDecodeError - Python Wiki
The UnicodeDecodeError normally happens when decoding an str string from a certain coding. Since codings map only a limited number of str ...
Read more >
UnicodeDecodeError: 'ascii' codec can't decode byte
The Python "UnicodeDecodeError: 'ascii' codec can't decode byte in position" occurs when we use the ascii codec to decode bytes that were ...
Read more >
Solving Unicode Problems in Python 2.7 - Azavea
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd1 in position 1: ordinal not in range(128) (Why is this so hard??)
Read more >
Overcoming frustration: Correctly using unicode in python2
In python, the unicode type stores an abstract sequence of code points. ... up with an exception being raised (UnicodeDecodeError or UnicodeEncodeError).
Read more >
UnicodeDecodeError on Python2 #2003 - pypa/setuptools
I'm trying to install wheel on Python 2 and getting an UnicodeDecodeError caused by a non-ASCII filename in the test tree of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found