summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2016-01-15 06:57:43 +0100
committerFlorian Bruhin <git@the-compiler.org>2016-01-18 21:39:29 +0100
commit0be44fd420ab40a830554df0c08a93abaab1df70 (patch)
tree7b95ff49d1f0c3cb5c5084261e37e0c8b04e638e
parentd9539ca6d8b8cf5cf290bf900b29641f5a3109ce (diff)
downloadqutebrowser-0be44fd420ab40a830554df0c08a93abaab1df70.tar.gz
qutebrowser-0be44fd420ab40a830554df0c08a93abaab1df70.zip
Avoid trying to load .netrc if $HOME isn't set.
This logged an error on Windows: ERROR misc networkmanager:on_authentication_required:269 Unable to read the netrc file Traceback (most recent call last): File "c:\python34\Lib\netrc.py", line 27, in __init__ file = os.path.join(os.environ['HOME'], ".netrc") File "C:\Users\florian\buildbot\slave\win8\build\.tox\py34\lib\os.py", line 633, in __getitem__ raise KeyError(key) from None KeyError: 'HOME' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\florian\buildbot\slave\win8\build\qutebrowser\browser\network\networkmanager.py", line 262, in on_authentication_required net = netrc.netrc() File "c:\python34\Lib\netrc.py", line 29, in __init__ raise OSError("Could not find .netrc: $HOME is not set") Since this case is pretty common, we don't want to log it - and checking the variable beforehand is easier than parsing the exception message. This should fix the failing tests on Windows.
-rw-r--r--qutebrowser/browser/network/networkmanager.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/qutebrowser/browser/network/networkmanager.py b/qutebrowser/browser/network/networkmanager.py
index 595765871..9b9eec705 100644
--- a/qutebrowser/browser/network/networkmanager.py
+++ b/qutebrowser/browser/network/networkmanager.py
@@ -19,6 +19,7 @@
"""Our own QNetworkAccessManager."""
+import os
import collections
import netrc
@@ -244,7 +245,10 @@ class NetworkManager(QNetworkAccessManager):
def on_authentication_required(self, reply, authenticator):
"""Called when a website needs authentication."""
user, password = None, None
- if not hasattr(reply, "netrc_used"):
+ if not hasattr(reply, "netrc_used") and 'HOME' in os.environ:
+ # We'll get an OSError by netrc if 'HOME' isn't available in
+ # os.environ. We don't want to log that, so we prevent it
+ # altogether.
reply.netrc_used = True
try:
net = netrc.netrc()