Skip to content
Myr

Handles request in event of HTTPError. Fixes Issue #2

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

Building of internal request object refactor

authored by Kenneth Reitz · committed by Kenneth Reitz · parent a82f4de · Browse files · 1 file+20 added−21 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+20 added−21 removed

  • other:+20 added−21 removed

1 file+20 added−21 removed

modified:requests/core.py+20 added-21 removed
97 unmodified lines
98 return opener.open99 else:100 return urllib2.urlopen101102 102103 def _build_response(self, resp):104 """Build internal Response object from given response."""105 106 self.response.status_code = resp.code107 self.response.headers = resp.info().dict108 self.response.content = resp.read()109 self.response.url = resp.url110111 def send(self, anyway=False):104 """Sends the request. Returns True of successfull, false if not.112 """Sends the request. Returns True of successful, false if not.113 If there was an HTTPError during transmission,114 self.response.status_code will contain the HTTPError code.115116 Once a request is successfully sent, `sent` will equal True.
25 unmodified lines
142 opener = self._get_opener()143144 try:145 resp = opener(req)138 self.response.status_code = resp.code139 self.response.headers = resp.info().dict140 if self.method == 'GET':141 self.response.content = resp.read()142 self.response.url = resp.url143146 self._build_response(resp)147 success = True148149 except urllib2.HTTPError as why:146 self.response.status_code = why.code150 self._build_response(why)151 success = False152153154 elif self.method == 'PUT':155 if (not self.sent) or anyway:
18 unmodified lines
174 try:175 opener = self._get_opener()176 resp = opener(req)177173 self.response.status_code = resp.code174 self.response.headers = resp.info().dict175 self.response.content = resp.read()176 self.response.url = resp.url177178 self._build_response(resp)179 success = True180181 except urllib2.HTTPError as why:181 self.response.status_code = why.code182 self._build_response(why)183 success = False184185186 elif self.method == 'POST':187 if (not self.sent) or anyway:
20 unmodified lines
208209 opener = self._get_opener()210 resp = opener(req)211210 self.response.status_code = resp.code211 self.response.headers = resp.info().dict212 self.response.content = resp.read()213 self.response.url = resp.url214212 self._build_response(resp)213 success = True214215 except urllib2.HTTPError as why:218 self.response.status_code = why.code216 sself._build_response(why)217 success = False218219 220 self.sent = True if success else False221
204 unmodified lines