Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysterious UnicodeDecodeError in python3 while building Docker container

I am creating a python 3 application. https://github.com/Omrigan/TED-analysis

To deploy I want to use Docker with Dockerfile located in root of my Github repo (you may check it). So, when I do "docker build ." I get an error on this line:

RUN pip3 install --upgrade  -r /root/ted_talks/requirements.txt

Log from console:

  Collecting httpretty==0.8.10 (from smart-open>=1.2.1->gensim->-r /root/ted_talks/requirements.txt (line 4))
  Downloading httpretty-0.8.10.tar.gz (41kB)
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-em459e9u/httpretty/setup.py", line 86, in <module>
        version=read_version(),
      File "/tmp/pip-build-em459e9u/httpretty/setup.py", line 46, in read_version
        finder.visit(ast.parse(local_file('httpretty', '__init__.py')))
      File "/tmp/pip-build-em459e9u/httpretty/setup.py", line 78, in <lambda>
        open(os.path.join(os.path.dirname(__file__), *f)).read()
      File "/usr/lib/python3.4/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 133: ordinal not in range(128)

So, what should I do?

like image 834
Omrigan Avatar asked Oct 30 '22 06:10

Omrigan


1 Answers

It seems that httpretty does some funky stuff to locate its version number - It opens one of the source files, which contains non-ascii chars, without declaring an encoding. In Python 3, this will use your locale, which in your case, seems to be corrupt or set to LANG=C|POSIX.

You have the following options:

  1. Download httpretty-0.8.10, edit httpretty/__init__.py and remove the non-ascii chars (ã).
  2. Set your locale to en_US.UTF-8
  3. I see that httpretty 0.8.14 has references to being Python 3 compliant. Try installing with:

    pip3 install httpretty==0.8.14
    
like image 169
Alastair McCormack Avatar answered Nov 08 '22 04:11

Alastair McCormack