From b49f4d9b0a4be941d01e2c5e2240107ad5052b17 Mon Sep 17 00:00:00 2001 From: Yabin Zheng Date: Mon, 3 Apr 2023 21:13:16 +0800 Subject: [PATCH] Fix 'json encoding' issue in Python 3.9.x and later versions. Current code tested on Py 3.10.9 --- crawler.py | 4 ++-- image_downloader_gui.spec | 2 +- requirements.txt | 9 +++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/crawler.py b/crawler.py index 054581cb..d94b763c 100644 --- a/crawler.py +++ b/crawler.py @@ -253,7 +253,7 @@ def decode_url(url): "https": "{}://{}".format(proxy_type, proxy)} res = requests.get(init_url, proxies=proxies, headers=g_headers) - init_json = json.loads(res.text.replace(r"\'", ""), encoding='utf-8', strict=False) + init_json = json.loads(res.text.replace(r"\'", "").encode("utf-8"), strict=False) total_num = init_json['listNum'] target_num = min(max_number, total_num) @@ -280,7 +280,7 @@ def process_batch(batch_no, batch_size): print(e) return image_urls response.encoding = 'utf-8' - res_json = json.loads(response.text.replace(r"\'", ""), encoding='utf-8', strict=False) + res_json = json.loads(response.text.replace(r"\'", ""), strict=False) for data in res_json['data']: # if 'middleURL' in data.keys(): # url = data['middleURL'] diff --git a/image_downloader_gui.spec b/image_downloader_gui.spec index 00965418..31caad03 100644 --- a/image_downloader_gui.spec +++ b/image_downloader_gui.spec @@ -23,6 +23,6 @@ exe = EXE(pyz, a.datas, name='image_downloader_gui', debug=False, - strip=True, + strip=False, upx=True, console=False ) diff --git a/requirements.txt b/requirements.txt index 9a85cc25..cf30d9e1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ -chromedriver_autoinstaller==0.4.0 -PyQt5==5.15.9 -requests==2.22.0 -selenium==4.8.2 +chromedriver-autoinstaller==0.4.0 +pyinstaller==5.9.0 +PyQt5==5.15.9 +requests==2.28.2 +selenium==4.8.3