def wrapper(*args, **kwargs): try: return f(*args, **kwargs) except requests.HTTPError as e: buf = BytesIO(e.response.content) raise TransportError( 'Error in requests\n' + traceback.format_exc(), e.response.status_code, buf, ) except requests.RequestException: raise TransportError( 'Error in requests\n' + traceback.format_exc(), 000, )
def open(self, request): try: url = request.url log.debug('opening (%s)', url) u2request = u2.Request(url) self.proxy = self.options.proxy return self.u2open(u2request) except HTTPError as e: raise TransportError(str(e), e.code, e.fp)
def send(self, request): url = request.url msg = request.message headers = request.headers self.proxy = self.options.proxy log.debug('sending:\n%s', request) resp = self.doOpen(url, data=msg, headers=headers, cookies=self.cookiejar) if resp.status_code not in (200,): raise TransportError("Error: %s"%resp.reason, resp.status_code, DummyFile(resp.content)) result = Reply(resp.status_code, resp.headers, resp.content) log.debug('received:\n%s', result) #except u2.HTTPError, e: # if e.code in (202,204): # result = None # else: # raise TransportError(e.msg, e.code, e.fp) return result
def send(self, request): result = None url = request.url msg = request.message headers = request.headers try: u2request = u2.Request(url, msg, headers) self.addcookies(u2request) self.proxy = self.options.proxy request.headers.update(u2request.headers) log.debug('sending:\n%s', request) fp = self.u2open(u2request) self.getcookies(fp, u2request) result = Reply(200, fp.headers, fp.read()) log.debug('received:\n%s', result) except HTTPError as e: if e.code in (202, 204): result = None else: raise TransportError(e.msg, e.code, e.fp) return result