• 爬虫两个问题


    1.requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='www.183xsw.com', port=443): Read timed out. (read timeout=10)
    2.requests.exceptions.ConnectionError: ('Connection aborted.', error(54, 'Connection reset by peer'))

    一个python的爬虫,爬取图片,出现以下报错:
    requests.exceptions.ConnectionError: (‘Connection aborted.’, error(54, ‘Connection reset by peer’))

    不是大问题,可能因为访问过于频繁,通过忽略可以解决,参考此网址
    http://www.it1352.com/743865.html

    有说原因:Mac openssl 版本过低,链接如下
    https://blog.csdn.net/u010801696/article/details/81570893
    这个方法正在尝试,还不知结果,前一种方法确认可行,不深究完全可以

    引用自algondon,侵删

    3错误提示:

    requests.exceptions.ConnectionError: HTTPSConnectionPool(host='baike.baidu.com', port=443):
    Max retries exceeded with url: https://baike.baidu.com/item/刘德华/114923
    (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fb51433af98>:
    Failed to establish a new connection: [Errno -2] Name or service not known',))
    经过一番查询,发现该错误是因为如下:

    http的连接数超过最大限制,默认的情况下连接是Keep-alive的,所以这就导致了服务器保持了太多连接而不能再新建连接。

    ip被封

    程序请求速度过快。

    解决办法如下:

    第一种方法

    try:
    page1 = requests.get(ap)
    except requests.exceptions.ConnectionError:
    r.status_code = "Connection refused"
    第二种方法:

    request的连接数过多而导致Max retries exceeded

    在header中不使用持久连接

    'Connection': 'close'

    requests.adapters.DEFAULT_RETRIES = 5
    第三种方法:

    针对请求请求速度过快导致程序报错。

    解决方法可以参考以下例子:

    import time

    while 1:
    try:
    page = requests.get(url)
    except:
    print("Connection refused by the server..")
    print("Let me sleep for 5 seconds")
    print("ZZzzzz...")
    time.sleep(5)
    print("Was a nice sleep, now let me continue...")
    continue
    http://www.chenxm.cc/post/536.html

  • 相关阅读:
    hdu 4638 Group 线段树
    hdu 4635 Strongly connected 强连通分量
    hdu 4604 Deque
    hdu 1000 A + B Problem
    数组相关
    文本文件相关
    硬件电路中VCC,VDD,VEE,VSS有什么区别
    VIPM链接LabVIEW问题
    Touch实现轻扫
    touchesMoved 实现拖拽
  • 原文地址:https://www.cnblogs.com/luowenConnor/p/11482921.html
Copyright © 2020-2023  润新知