data encoding must be done after calling an auth provider which might change the...
authorAndre Graf <andre@dergraf.org>
Wed, 29 Aug 2012 19:20:11 +0000 (21:20 +0200)
committerAndre Graf <andre@dergraf.org>
Wed, 29 Aug 2012 19:20:11 +0000 (21:20 +0200)
requests/models.py

index 29c06c6baacb44a06c7600133249fbd188bc397d..66c50939ccf7d7467048a80fd7fe2f8504d67f57 100644 (file)
@@ -499,6 +499,21 @@ class Request(object):
                 datetime.now().isoformat(), self.method, url
             ))
 
+        # Use .netrc auth if none was provided.
+        if not self.auth and self.config.get('trust_env'):
+            self.auth = get_netrc_auth(url)
+
+        if self.auth:
+            if isinstance(self.auth, tuple) and len(self.auth) == 2:
+                # special-case basic HTTP auth
+                self.auth = HTTPBasicAuth(*self.auth)
+
+            # Allow auth to make its changes.
+            r = self.auth(self)
+
+            # Update self to reflect the auth changes.
+            self.__dict__.update(r.__dict__)
+
         # Nottin' on you.
         body = None
         content_type = None
@@ -519,21 +534,6 @@ class Request(object):
         if (content_type) and (not 'content-type' in self.headers):
             self.headers['Content-Type'] = content_type
 
-        # Use .netrc auth if none was provided.
-        if not self.auth and self.config.get('trust_env'):
-            self.auth = get_netrc_auth(url)
-
-        if self.auth:
-            if isinstance(self.auth, tuple) and len(self.auth) == 2:
-                # special-case basic HTTP auth
-                self.auth = HTTPBasicAuth(*self.auth)
-
-            # Allow auth to make its changes.
-            r = self.auth(self)
-
-            # Update self to reflect the auth changes.
-            self.__dict__.update(r.__dict__)
-
         _p = urlparse(url)
         no_proxy = filter(lambda x: x.strip(), self.proxies.get('no', '').split(','))
         proxy = self.proxies.get(_p.scheme)