Style changes thanks to @sigmavirus24.
authorCory Benfield <lukasaoz@gmail.com>
Sat, 22 Mar 2014 21:11:33 +0000 (21:11 +0000)
committerCory Benfield <lukasaoz@gmail.com>
Sat, 22 Mar 2014 21:11:33 +0000 (21:11 +0000)
requests/sessions.py

index 65902d87a9b75b1d52752a75cb0cf05c2b061609..79ea7773e1e7ec3fdc84b88a50dacff2b24c86cb 100644 (file)
@@ -221,22 +221,21 @@ class SessionRedirectMixin(object):
             environ_proxies = get_environ_proxies(url)
             scheme = urlparse(url).scheme
 
-            try:
+            proxy = environ_proxies.get(scheme)
+
+            if proxy:
                 new_proxies.setdefault(scheme, environ_proxies[scheme])
-            except KeyError:
-                pass
 
         if 'Proxy-Authorization' in headers:
             del headers['Proxy-Authorization']
 
         try:
             username, password = get_auth_from_url(new_proxies[scheme])
-            if username and password:
-                headers['Proxy-Authorization'] = _basic_auth_str(
-                    username, password
-                )
         except KeyError:
-            pass
+            username, password = None, None
+
+        if username and password:
+            headers['Proxy-Authorization'] = _basic_auth_str(username, password)
 
         return new_proxies