m-click / requests_pkcs12

Add PKCS#12 support to the Python requests library in a clean way, without monkey patching or temporary files
ISC License
124 stars 33 forks source link

Fails to install using python36 when system encoding is not UTF-8 #19

Closed jaedolph closed 4 years ago

jaedolph commented 4 years ago

Noticed a small issue when trying to install this from a source distribution on an system where the locale is set to POSIX and python version is 3.6 (this was the situation we had on a Jenkins build box we were using this project on)

[test@localhost requests_pkcs12]$ export LANG=POSIX
[test@localhost requests_pkcs12]$ export LC_ALL=POSIX
[test@localhost requests_pkcs12]$ locale
LANG=POSIX
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=POSIX
[test@localhost requests_pkcs12]$ pip3 install .
Processing /var/tmp/requests_pkcs12
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-k4kckmm2-build/setup.py", line 6, in <module>
        long_description=open('README.rst').read(),
      File "/usr/lib64/python3.6/encodings/ascii.py", line 26, in decode
        return codecs.ascii_decode(input, self.errors)[0]
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 2244: ordinal not in range(128)

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-k4kckmm2-build/

We figured out this is due to the open() function call in setup.py not being explicit on the encoding (uses the system encoding returned locale.getpreferredencoding())

In our case the simple fix was to run this before the build:

export LC_ALL=en_US.utf8

I have also done a PR that makes sure the README.rst can be decoded correctly by setup.py regardless of the system locale. https://github.com/m-click/requests_pkcs12/pull/18https://github.com/m-click/requests_pkcs12/pull/18

vog commented 4 years ago

Thanks for the contribution!

I had to fix a minor coding style issue (see commit 992b4051d34eb9a897dfc4faa4d0621611cee52d), but apart from that it was all fine.

I created a new release 1.7.