예제 #1
0
 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,
         )
예제 #2
0
 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)
예제 #3
0
파일: http.py 프로젝트: yildizib/olap
 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
예제 #4
0
 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