コード例 #1
0
 def exception_handler(req, ex):
     msg = "Failed to download " + req.url
     if isinstance(ex, requests.exceptions.Timeout):
         msg = "Connection timed out: %(ex)s (%(url)s)" % {"ex": ex.__str__(), "url": req.url}
     elif isinstance(ex, requests.exceptions.RequestException):
         msg = "Error downloading: %(ex)s (%(url)s)" % {"ex": ex, "url": req.url}
     else:
         msg = " ".join([msg, str(ex)])
     errors.append(req.url)
     logger.error(msg)
コード例 #2
0
ファイル: downloader.py プロジェクト: yuzhucu/PyTradeLib
 def exception_handler(req, ex):
     msg = 'Failed to download ' + req.url
     if isinstance(ex, requests.exceptions.Timeout):
         msg = 'Connection timed out: %(ex)s (%(url)s)' % {'ex': ex.__str__(), 'url': req.url}
     elif isinstance(ex, requests.exceptions.RequestException):
         msg = 'Error downloading: %(ex)s (%(url)s)' % {'ex': ex, 'url': req.url}
     else:
         msg = ' '.join([msg, str(ex)])
     errors.append(req.url)
     logger.error(msg)
コード例 #3
0
 def _download(self, url):
     logger.info("Download started: " + url)
     try:
         r = requests.get(url)
         logger.info("Download completed: " + url)
         if r.status_code == 200:
             return r.content
         r.raise_for_status()
     except requests.exceptions.Timeout as e:
         logger.error("Connection timed out: " + e.__str__())
     except requests.exceptions.RequestException as e:
         logger.error("Error downloading: " + e.__str__())
     return None
コード例 #4
0
ファイル: downloader.py プロジェクト: yuzhucu/PyTradeLib
 def _download(self, url):
     logger.info('Download started: ' + url)
     try:
         r = requests.get(url)
         logger.info('Download completed: ' + url)
         if r.status_code == 200:
             return r.content
         r.raise_for_status()
     except requests.exceptions.Timeout as e:
         logger.error('Connection timed out: ' + e.__str__())
     except requests.exceptions.RequestException as e:
         logger.error('Error downloading: ' + e.__str__())
     return None