Skip to content

Decoding Error when reading license file. #35

@harahu

Description

@harahu

I ran pip-licenses inside a docker container of mine, and got the following exception:

Traceback (most recent call last):
  File "/usr/local/bin/pip-licenses", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/dist-packages/piplicenses.py", line 598, in main
    output_string = create_output_string(args)
  File "/usr/local/lib/python3.5/dist-packages/piplicenses.py", line 386, in create_output_string
    table = create_licenses_table(args, output_fields)
  File "/usr/local/lib/python3.5/dist-packages/piplicenses.py", line 200, in create_licenses_table
    for pkg in get_packages(args):
  File "/usr/local/lib/python3.5/dist-packages/piplicenses.py", line 185, in get_packages
    pkg_info = get_pkg_info(pkg)
  File "/usr/local/lib/python3.5/dist-packages/piplicenses.py", line 141, in get_pkg_info
    (license_file, license_text) = get_pkg_license_file(pkg)
  File "/usr/local/lib/python3.5/dist-packages/piplicenses.py", line 128, in get_pkg_license_file
    file_lines = license_file_handle.readlines()
  File "/usr/lib/python3.5/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 10: ordinal not in range(128)

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:

with open(test_file, encoding='utf-8', errors='ignore') as license_file_handle:

Not sure always assuming utf-8 is a good idea, though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions