当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.ReadTimeoutError方法代码示例

本文整理汇总了Python中requests.packages.urllib3.exceptions.ReadTimeoutError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.ReadTimeoutError方法的具体用法?Python exceptions.ReadTimeoutError怎么用?Python exceptions.ReadTimeoutError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在requests.packages.urllib3.exceptions的用法示例。


在下文中一共展示了exceptions.ReadTimeoutError方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_connection_errors

# 需要导入模块: from requests.packages.urllib3 import exceptions [as 别名]
# 或者: from requests.packages.urllib3.exceptions import ReadTimeoutError [as 别名]
def handle_connection_errors(client):
    try:
        yield
    except SSLError as e:
        log.error('SSL error: %s' % e)
        raise ConnectionError()
    except RequestsConnectionError as e:
        if e.args and isinstance(e.args[0], ReadTimeoutError):
            log_timeout_error(client.timeout)
            raise ConnectionError()
        exit_with_error(get_conn_error_message(client.base_url))
    except APIError as e:
        log_api_error(e, client.api_version)
        raise ConnectionError()
    except (ReadTimeout, socket.timeout):
        log_timeout_error(client.timeout)
        raise ConnectionError()
    except Exception as e:
        if is_windows():
            import pywintypes
            if isinstance(e, pywintypes.error):
                log_windows_pipe_error(e)
                raise ConnectionError()
        raise 
开发者ID:QData,项目名称:deepWordBug,代码行数:26,代码来源:errors.py

示例2: get

# 需要导入模块: from requests.packages.urllib3 import exceptions [as 别名]
# 或者: from requests.packages.urllib3.exceptions import ReadTimeoutError [as 别名]
def get(url, params=None, headers=None, retry=3, **kwargs):
    """
    :param url: 请求base url
    :param params: url params参数
    :param headers: http head头信息
    :param retry: 重试次数,默认retry=3
    :param kwargs: 透传给requests.get,可设置ua等,超时等参数
    """
    req_count = 0
    while req_count < retry:
        # 重试retry次
        try:
            resp = requests.get(url=url, params=params, headers=headers, **kwargs)
            if resp.status_code == 200 or resp.status_code == 206:
                # 如果200,206返回,否则继续走重试
                return resp
        except ReadTimeoutError:
            # 超时直接重试就行,不打日志
            pass
        except Exception as e:
            logging.exception(e)
        req_count += 1
        time.sleep(0.5)
        continue
    return None 
开发者ID:bbfamily,项目名称:abu,代码行数:27,代码来源:ABuNetWork.py

示例3: send

# 需要导入模块: from requests.packages.urllib3 import exceptions [as 别名]
# 或者: from requests.packages.urllib3.exceptions import ReadTimeoutError [as 别名]
def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None):
        try:
            ret = super().send(request, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies)
        except ConnectionError as error:
            if hasattr(error.args[0], "reason") and isinstance(error.args[0].reason, ReadTimeoutError):
                raise ReadTimeout(error.args[0], request=request)
            raise error
        else:
            return ret 
开发者ID:penetrate2hack,项目名称:ITWSV,代码行数:11,代码来源:crawler.py

示例4: streamer

# 需要导入模块: from requests.packages.urllib3 import exceptions [as 别名]
# 或者: from requests.packages.urllib3.exceptions import ReadTimeoutError [as 别名]
def streamer(credentials, queries, refresh, sentiment=False, debug=False):
    keywords = [i for j in queries.values() for i in j]

    # User Error Checks
    if len(queries)  <= 0:  print("Error: You must include at least one query."); return
    if len(queries)  >= 10: print("Warning: Fewer than ten query recommended.")
    if len(keywords) <= 0:  print("Error: You must include at least one keyword."); return
    if len(keywords) >= 20: print("Warning: Fewer than twenty keywords recommended.")
    if refresh       <= 0:  print("Error: Refresh rate must be greater than 0"); return

    auth = tweepy.OAuthHandler(credentials[0], credentials[1])
    auth.set_access_token(credentials[2], credentials[3])

    if sentiment:
        global SentimentIntensityAnalyzer
        from nltk.sentiment.vader import SentimentIntensityAnalyzer

    while True:

        # Start streaming -----------------------------
        try:
            print("Streaming Now...")
            listener = Listener(auth, queries, refresh, sentiment, debug)
            stream = tweepy.Stream(auth, listener)
            stream.filter(track=keywords)

        except (Timeout, ConnectionError, ReadTimeoutError):
            print("{0} Error: Connection Dropped\n".format(time.strftime('%m/%d/%Y %H:%M:%S')))
            print("Re-establishing Connection...")

        time.sleep((15*60)+1) # Wait at least 15 minutes before restarting listener

        # --------------------------------------------- 
开发者ID:anfederico,项目名称:Stocktalk,代码行数:35,代码来源:streaming.py

示例5: handleUrlDownload

# 需要导入模块: from requests.packages.urllib3 import exceptions [as 别名]
# 或者: from requests.packages.urllib3.exceptions import ReadTimeoutError [as 别名]
def handleUrlDownload(request):
    response = {'status': 'error'}
    form = UrlDownloadForm(request.POST)
    if not form.is_valid():
        response['message'] = _('Invalid form.')
        return response, 400
    content = None
    try:
        r = requests.get(form.cleaned_data[
                         'url'], timeout=settings.URL_DEPOSIT_DOWNLOAD_TIMEOUT, stream=True)
        r.raise_for_status()
        content = r.raw.read(settings.DEPOSIT_MAX_FILE_SIZE+1, decode_content=False)

        if len(content) > settings.DEPOSIT_MAX_FILE_SIZE:
            response['message'] = _('File too large.')

        content_type = r.headers.get('content-type')
        if 'text/html' in content_type:
            response['message'] = (  # Left as one line for compatibility purposes
                _('Invalid content type: this link points to a web page, we need a direct link to a PDF file.'))

    except requests.exceptions.SSLError:
        response['message'] = _('Invalid SSL certificate on the remote server.')
    except requests.exceptions.Timeout:
        response['message'] = _('Invalid URL (server timed out).')
    except requests.exceptions.RequestException:
        response['message'] = _('Invalid URL.')
    except ReadTimeoutError:
        response['message'] = _('Invalid URL (server timed out).')
    except HTTPError:
        response['message'] = _('Invalid URL.')

    if 'message' in response:
        return response, 403

    orig_name = form.cleaned_data['url']

    response = save_pdf(request.user, orig_name, content)

    if response['status'] == 'error':
        return response, 403

    return response 
开发者ID:dissemin,项目名称:dissemin,代码行数:45,代码来源:views.py


注:本文中的requests.packages.urllib3.exceptions.ReadTimeoutError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。