Skip to content
Myr

parameters working for GETs now. This is awesome.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kenneth Reitz · committed by Kenneth Reitz · parent 327d923 · Browse files · 1 file+32 added−23 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+32 added−23 removed

  • other:+32 added−23 removed

1 file+32 added−23 removed

modified:requests/core.py+32 added-23 removed
48 unmodified lines
49 if not value.lower() in self._METHODS:50 raise InvalidMethod()51 52 object.__setattr__(self, name, value)53 53 54 55 def _checks(self):56 pass5758 59 def _get_opener(self):60 """ Creates appropriate opener object for urllib2.61 """62 63 if self.auth:6465 # create a password manager66 authr = urllib2.HTTPPasswordMgrWithDefaultRealm()6768 authr.add_password(None, self.url, self.auth.username, self.auth.password)69 handler = urllib2.HTTPBasicAuthHandler(authr)70 opener = urllib2.build_opener(handler)7172 # use the opener to fetch a URL73 return opener.open74 else:75 return urllib2.urlopen7677 78 def send(self, anyway=False):79 """Sends the request. 80 81 :param anyway: If True, request will be sent, even if it has already been sent.
2 unmodified lines
84 85 if self.method.lower() == 'get':86 if (not self.sent) or anyway:87 try:68 req = urllib2.Request(self.url)6970 if self.headers:71 r.headers = self.headers7273 # url encode form data if it's a dict74 if isinstance(self.data, dict):75 req.params = urllib.urlencode(self.params)88 # url encode GET params if it's a dict89 if isinstance(self.params, dict):90 params = urllib.urlencode(self.params)91 else:77 req.params = self.paams9279 if self.auth:93 params = self.params9481 # create a password manager82 password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()95 req = urllib2.Request("%s?%s" % (self.url, params))9684 # Add the username and password.85 # If we knew the realm, we could use it instead of ``None``.86 password_mgr.add_password(None, self.url, self.auth.username, self.auth.password)87 handler = urllib2.HTTPBasicAuthHandler(password_mgr)88 opener = urllib2.build_opener(handler)97 if self.headers:98 req.headers = self.headers9990 # use the opener to fetch a URL91 resp = opener.open(req)92 else:93 resp = urllib2.urlopen(req)100 opener = self._get_opener()101 resp = opener(req)102103 self.response.status_code = resp.code104 self.response.headers = resp.info().dict105 self.response.content = resp.read()106107 success = True108109102 except Exception:110 except RequestException:111 raise RequestException112 113 114 elif self.method.lower() == 'head':
105 unmodified lines
220 r = Request()221 222 r.method = 'GET'223 r.url = url224 r.params = params225 r.headers = headers226 r.auth = _detect_auth(url, auth)227 228 r.send()
98 unmodified lines