From 7d08831af194fd5ae48e9f2b4bd4e936bebb1fba Mon Sep 17 00:00:00 2001 From: Starfer Date: Sat, 29 Apr 2023 22:40:10 +0400 Subject: [PATCH 1/2] Fixed issue with non-latin characters --- pinterest-downloader.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pinterest-downloader.py b/pinterest-downloader.py index a037b33..7673ec0 100755 --- a/pinterest-downloader.py +++ b/pinterest-downloader.py @@ -197,7 +197,7 @@ def get_session(ver_i, proxies, cookie_file): 'User-Agent': UA, 'Accept': 'application/json, text/javascript, */*, q=0.01', 'Accept-Language': 'en-US,en;q=0.5', - 'Accept-Encoding': 'gzip, deflate, br', + 'Accept-Encoding': 'gzip, deflate, utf-8', 'Referer': 'https://www.pinterest.com/', 'X-Requested-With': 'XMLHttpRequest', 'X-APP-VERSION': VER[ver_i], @@ -1080,7 +1080,7 @@ def write_log(arg_timestamp_log, url_path, shortform cprint(''.join([ HIGHER_YELLOW, '%s' % ('\nWrite log increment from last log stored index failed. Fallback to -lt\n\n') ]), attrs=BOLD_ONLY, end='' ) log_timestamp = 'log-pinterest-downloader_' + datetime.now().strftime('%Y-%m-%d %H.%M.%S') log_path = os.path.join(save_dir, '{}'.format( sanitize(log_timestamp) + '.log' )) - with open(log_path, 'w') as f: # Refer below else: + with open(log_path, 'w', encoding='utf-8') as f: # Refer below else: f.write('Pinterest Downloader: Version ' + str(__version__) + '\n\n') else: @@ -1097,7 +1097,7 @@ def write_log(arg_timestamp_log, url_path, shortform if img_total == 0: # No need create log when empty folder, but still created .urls above return False else: - with open(log_path, 'w') as f: # Reset before append + with open(log_path, 'w', encoding='utf-8') as f: # Reset before append f.write('Pinterest Downloader: Version ' + str(__version__) + '\n\n') # Easy to recognize if future want to change something f.write('Input URL: https://www.pinterest.com/' + url_path.rstrip('/') + '/\n') # Reuse/refer when want to update if shortform: # single pin no need From 5265c3ebbbe608aa0a732d3a027e7b6ce23afbfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E6=9E=9C=E7=9A=9E?= Date: Mon, 1 May 2023 04:10:08 +0800 Subject: [PATCH 2/2] Not proper way to fix the encoding error. Gzip is not a standard option in Accept-Encoding, but removing 'br' can still fix the issue. However, to avoid using non-modern browsers without gzip support, it may be better to force users to install Brotli. This error occurred on my newly installed Python on Windows; there were no issues on my Linux machine. --- pinterest-downloader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pinterest-downloader.py b/pinterest-downloader.py index 7673ec0..7b2765b 100755 --- a/pinterest-downloader.py +++ b/pinterest-downloader.py @@ -197,7 +197,7 @@ def get_session(ver_i, proxies, cookie_file): 'User-Agent': UA, 'Accept': 'application/json, text/javascript, */*, q=0.01', 'Accept-Language': 'en-US,en;q=0.5', - 'Accept-Encoding': 'gzip, deflate, utf-8', + 'Accept-Encoding': 'gzip, deflate, br', 'Referer': 'https://www.pinterest.com/', 'X-Requested-With': 'XMLHttpRequest', 'X-APP-VERSION': VER[ver_i],