-
Notifications
You must be signed in to change notification settings - Fork 45
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
Decoding Error when reading license file. #35
Comments
Thank you for the report. It did not reproduce in my environment. $ pip install "Werkzeug==0.14.1"
$ pip install pip-licenses
$ pip-licenses -l --format=j
[
{
"License": "BSD",
"LicenseFile": "/home/raimon49/.anyenv/envs/pyenv/versions/3.6.4/envs/venv-3.6.4-Werkzeug/lib/python3.6/site-packages/Werkzeug-0.14.1.dist-info/LICENSE.txt",
"LicenseText": "Copyright \u00a9 2007 by the Pallets team.\n\nSome rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\n* Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n* Redistributions in binary form must reproduce the above copyright\n notice, this list of conditions and the following disclaimer in the\n documentation and/or other materials provided with the distribution.\n\n* Neither the name of the copyright holder nor the names of its\n contributors may be used to endorse or promote products derived from\n this software without specific prior written permission.\n\nTHIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND\nCONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\nBUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\nFITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\nCOPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\nINCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\nNOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\nUSE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\nTHIS SOFTWARE AND DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGE.\n",
"Name": "Werkzeug",
"Version": "0.14.1"
}
] If you can reproduce this exception, I will incorporate your suggestion into a file open. Is there any other information? |
I did some more research. Looking at the documentation for Python's
Where most out-of-the-box personal computers have sensible locale setting, often docker containers do not. Calling
I replicated this problem outside of the container with this script, passing the file path as an argument: import sys
with open(sys.argv[1], encoding='ANSI_X3.4-1968') as license_file:
lines = license_file.readlines()
for line in lines:
print(line) I am not sure what is the preferred solution to this. As suggested in my initial post, I think you want to either specify an encoding (like utf-8), or provide some error handling, through the errors argument. The different options have different consequences which I am unsure about how will affect the usability and stability of your package across different contexts it will be used. |
Ah, I understand. The environment variable e.g.) # execute env command in my docker container
/opt/piplicenses # env
HOSTNAME=e6b341a614a9
PYTHON_PIP_VERSION=19.0.3
SHLVL=1
HOME=/root
GPG_KEY=0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D
TERM=xterm
PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
LANG=C.UTF-8
PYTHON_VERSION=3.7.2
PWD=/opt/piplicenses It is recommended to set locale and Thank you for your detailed research. Can you solve this answer? |
Mine is based on the official TensorFlow one, for reference. But yeah, I can close this. |
Important Starting with PEP 263 in 2001, |
I ran pip-licenses inside a docker container of mine, and got the following exception:
The offending license file was:
/usr/local/lib/python3.5/dist-packages/Werkzeug-0.14.1.dist-info/LICENSE.txt
I was able to resolve the issue by editing line 127 in piplicenses.py:
Not sure always assuming utf-8 is a good idea, though.
The text was updated successfully, but these errors were encountered: