Skip to content

Commit

Permalink
Fix 'json encoding' issue in Python 3.9.x and later versions. Current…
Browse files Browse the repository at this point in the history
… code tested on Py 3.10.9
  • Loading branch information
sczhengyabin committed Apr 3, 2023
1 parent 91f6ebd commit b49f4d9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion image_downloader_gui.spec
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ exe = EXE(pyz,
a.datas,
name='image_downloader_gui',
debug=False,
strip=True,
strip=False,
upx=True,
console=False )
9 changes: 5 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b49f4d9

Please sign in to comment.