From caf95742daa7af6e61f9898ff5f9aa364f392a18 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 1 Jun 2020 07:18:13 +1000 Subject: [PATCH] handle unicode hostnames https://anki.tenderapp.com/discussions/ankidesktop/41915-something-wrong-and-i-cant-start-anki --- qt/aqt/__init__.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/qt/aqt/__init__.py b/qt/aqt/__init__.py index 145e52e35..4ad1fa2c2 100644 --- a/qt/aqt/__init__.py +++ b/qt/aqt/__init__.py @@ -477,14 +477,23 @@ section of the manual, and ensure that location is not read-only.""", # proxy configured? from urllib.request import proxy_bypass, getproxies - if "http" in getproxies(): - # if it's not set up to bypass localhost, we'll - # need to disable proxies in the webviews - if not proxy_bypass("127.0.0.1"): - print("webview proxy use disabled") - proxy = QNetworkProxy() - proxy.setType(QNetworkProxy.NoProxy) - QNetworkProxy.setApplicationProxy(proxy) + disable_proxies = False + try: + if "http" in getproxies(): + # if it's not set up to bypass localhost, we'll + # need to disable proxies in the webviews + if not proxy_bypass("127.0.0.1"): + disable_proxies = True + except UnicodeDecodeError: + # proxy_bypass can't handle unicode in hostnames; assume we need + # to disable proxies + disable_proxies = True + + if disable_proxies: + print("webview proxy use disabled") + proxy = QNetworkProxy() + proxy.setType(QNetworkProxy.NoProxy) + QNetworkProxy.setApplicationProxy(proxy) # we must have a usable temp dir try: