Skip to content
Myr

Added new HTTPError handing mechanisms.

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 d6fa43f · Browse files · 1 file+19 added−11 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+19 added−11 removed

  • other:+19 added−11 removed

1 file+19 added−11 removed

modified:requests/core.py+19 added-11 removed
157 unmodified lines
158 # url encode GET params if it's a dict159 if isinstance(self.params, dict):160 params = urllib.urlencode(self.params)161 else:162162 params = self.params163164 req = _Request(("%s?%s" % (self.url, params)), method=self.method)165
4 unmodified lines
170171 try:172 resp = opener(req)173 self._build_response(resp)175 success = True174 self.response.ok = True175176 except urllib2.HTTPError as why:177 self._build_response(why)179 success = False178 self.response.error = why179180181 elif self.method == 'PUT':182 if (not self.sent) or anyway:
19 unmodified lines
202 opener = self._get_opener()203 resp = opener(req)204205 self._build_response(resp)207 success = True206 self.response.ok = True207208 except urllib2.HTTPError as why:209 self._build_response(why)211 success = False210 self.response.error = why211212213 elif self.method == 'POST':214 if (not self.sent) or anyway:
16 unmodified lines
231 else:232 req.data = self.data233234 try:236235 opener = self._get_opener()236 resp = opener(req)237238 self._build_response(resp)241 success = True239 self.response.ok = True240241 except urllib2.HTTPError as why:242 self._build_response(why)245 success = False246243 self.response.error = why244 248 self.sent = True if success else False245 self.sent = self.response.ok246 250 return success247 return self.sent248 249250class Response(object):251 """The :class:`Request` object. All :class:`Request` objects contain a
5 unmodified lines
257 self.content = None258 self.status_code = None259 self.headers = dict()260 self.url = None261 self.ok = False262 self.error = False263 264 def __repr__(self):265 return '<Response [%s]>' % (self.status_code)266 267 def __nonzero__(self):268 """Returns true if status_code is 'OK'."""269 return not self.error270 271 def raise_for_response(self):272 """Raises stored HTTPError if one exists."""273 if self.error:274 raise self.error275276277 278class AuthObject(object):
193 unmodified lines