gabrielfalcao / HTTPretty

Intercept HTTP requests at the Python socket level. Fakes the whole socket module
https://httpretty.readthedocs.org
MIT License
2.11k stars 276 forks source link

Unable to install on Python3 if either LANG not set or specified locale not installed. #243

Open scraperdragon opened 9 years ago

scraperdragon commented 9 years ago

Specifically, the ã in your name in __init__.py etc. causes read()ing from that file in setup.py to fail since it's not ASCII.

Leaving one or both of the lines commented below causes pip3 to fail to install. Uncommenting both makes it work successfully.

Dockerfile:

FROM ubuntu:14.04

RUN apt-get update
RUN apt-get install -y git
RUN apt-get install -y python3-pip

#RUN locale-gen en_GB.UTF-8

RUN mkdir /home/nobody && \
    chown nobody /home/nobody
USER nobody
ENV HOME=/home/nobody \
#    LANG=en_GB.UTF-8 \
    PATH=/home/nobody/.local/bin:$PATH
WORKDIR /home/nobody
nobody@4d4e2d0d4272:~$ pip3 install httpretty
Downloading/unpacking httpretty
  Downloading httpretty-0.8.8.tar.gz (40kB): 40kB downloaded
  Running setup.py (path:/tmp/pip_build_nobody/httpretty/setup.py) egg_info for package httpretty
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "/tmp/pip_build_nobody/httpretty/setup.py", line 86, in <module>
        version=read_version(),
      File "/tmp/pip_build_nobody/httpretty/setup.py", line 46, in read_version
        finder.visit(ast.parse(local_file('httpretty', '__init__.py')))
      File "/tmp/pip_build_nobody/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)
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 17, in <module>

  File "/tmp/pip_build_nobody/httpretty/setup.py", line 86, in <module>

    version=read_version(),

  File "/tmp/pip_build_nobody/httpretty/setup.py", line 46, in read_version

    finder.visit(ast.parse(local_file('httpretty', '__init__.py')))

  File "/tmp/pip_build_nobody/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)

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_nobody/httpretty
Storing debug log for failure in /home/nobody/.pip/pip.log
bpicolo commented 9 years ago

The default encoding for python3 is utf8, not to mention init explicitly declares utf-8 encoding. You definitely need to have utf8 installed properly on the system for python3 to work as expected in general. (The library appears to be doing the right thing here).

"ENV LANG en_US.UTF-8" is a pretty typical line in my Docker builds. It's what most Linux/Unix systems give you out of box these days. : )

deuxpi commented 9 years ago

I have a UTF-8 locale properly set and I still get this error (in my case, a run of tox with a Python 3.4 environment).