ConnectionError: HTTPSConnectionPool(host=‘cq.feibaos.com’, port=443): Max retries exceeded with url: /news/lists-notice.html?req=t11-320100&word=&idx=49 (Caused by NewConnectionError(’<urllib3.connection.VerifiedHTTPSConnection object at 0x7fc465493f10>: Failed to establish a new connection: [Errno -2] Name or service not known’))
使用session代替get
代码如下:
import requests
s=requests.session()
s.keep_alive=False
s.get(url=url)
本文介绍了一种常见的Python请求错误“MaxRetriesExceededURL”,通常发生在网络连接不稳定或目标服务器无法访问时。文章提供了一个解决方案,即使用requests库的session对象替代直接的get请求,并展示了具体的代码实现。

2万+

被折叠的 条评论
为什么被折叠?



