diff --git a/requirements.txt b/requirements.txt --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ requests setuptools vcversioner +chardet diff --git a/swh/loader/npm/client.py b/swh/loader/npm/client.py --- a/swh/loader/npm/client.py +++ b/swh/loader/npm/client.py @@ -7,6 +7,7 @@ import logging import os +import chardet import requests from swh.core import tarball @@ -196,8 +197,10 @@ # parse package.json file to add its content to revision metadata package_json_path = os.path.join(package_path, 'package.json') package_json = {} - with open(package_json_path, "r") as package_json_file: - package_json = json.load(package_json_file) + with open(package_json_path, "rb") as package_json_file: + package_json_bytes = package_json_file.read() + file_encoding = chardet.detect(package_json_bytes)['encoding'] + package_json = json.loads(package_json_bytes.decode(file_encoding)) # extract author from package.json author = extract_npm_package_author(package_json)