国产成人AV无码一二三区,少女1到100集,国产精品久久久久精品综合紧,巜公妇之诱感肉欲HD在线播放

文章 > Python常见问题 > python使用requests语句报错的原因有哪些

python使用requests语句报错的原因有哪些

头像

silencement

2019-08-27 10:22:567532浏览 · 0收藏 · 0评论

python中使用requests语句报错的原因主要有以下几种情况:

1 连接超时

服务器在指定时间内没有应答,抛出 requests.exceptions.ConnectTimeout

requests.get('http://github.com', timeout=0.001)

# 抛出错误

requests.exceptions.ConnectTimeout: HTTPConnectionPool(host='github.com', port=80): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7f1b16da75f8>, 'Connection to github.com timed out. (connect timeout=0.001)'))

2. 连接、读取超时

若分别指定连接和读取的超时时间,服务器在指定时间没有应答,抛出 requests.exceptions.ConnectTimeout 

- timeout=([连接超时时间], [读取超时时间]) 

- 连接:客户端连接服务器并并发送http请求服务器 

- 读取:客户端等待服务器发送第一个字节之前的时间

requests.get('http://github.com', timeout=(6.05, 0.01))
# 抛出错误
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='github.com', port=80): Read timed out. 
(read timeout=0.01)

3. 未知的服务器

抛出 requests.exceptions.ConnectionError
requests.get('http://github.comasf', timeout=(6.05, 27.05))
# 抛出错误
requests.exceptions.ConnectionError: HTTPConnectionPool(host='github.comasf', port=80): Max retries exceeded 
with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f75826665f8>: 
Failed to establish a new connection: [Errno -2] Name or service not known',))

4. 代理连接不上

代理服务器拒绝建立连接,端口拒绝连接或未开放,抛出 requests.exceptions.ProxyError

requests.get('http://github.com', timeout=(6.05, 27.05), proxies={"http": "192.168.10.1:800"})
# 抛出错误
requests.exceptions.ProxyError: HTTPConnectionPool(host='192.168.10.1', port=800): Max retries exceeded with 
url: http://github.com/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.
connection.HTTPConnection object at 0x7fce3438c6d8>: Failed to establish a new connection: [Errno 111] 
Connection refused',)))

5. 连接代理超时

代理服务器没有响应 requests.exceptions.ConnectTimeout

requests.get('http://github.com', timeout=(6.05, 27.05), proxies={"http": "10.200.123.123:800"})
# 抛出错误
requests.exceptions.ConnectTimeout: HTTPConnectionPool(host='10.200.123.123', port=800): Max retries exceeded 
with url: http://github.com/ (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 
0x7fa8896cc6d8>, 'Connection to 10.200.123.123 timed out. (connect timeout=6.05)'))

6. 代理读取超时

说明与代理建立连接成功,代理也发送请求到目标站点,但是代理读取目标站点资源超时 

即使代理访问很快,如果代理服务器访问的目标站点超时,这个锅还是代理服务器背 

假定代理可用,timeout就是向代理服务器的连接和读取过程的超时时间,不用关心代理服务器是否连接和读取成功

requests.get('http://github.com', timeout=(2, 0.01), proxies={"http": "192.168.10.1:800"})
# 抛出错误
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='192.168.10.1:800', port=1080): Read timed out. (read 
timeout=0.5)

7. 网络环境异常

可能是断网导致,抛出 requests.exceptions.ConnectionError

requests.get('http://github.com', timeout=(6.05, 27.05))
# 抛出错误
requests.exceptions.ConnectionError: HTTPConnectionPool(host='github.com', port=80): Max retries exceeded with 
url: / 
(Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fc8c17675f8>: Failed to 
establish a new 
connection: [Errno -3] Temporary failure in name resolution',))
关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

苏苏的骚浪短笔趣阁小说| 日日AV夜夜添久久奶无码| 《酒店激战》动漫1-5集免费观.. 《魅魔之耻》1~4集免费看 | 美国禁忌2在线观看电视剧| 《魅魔之耻》1~4集免费看| 爸老师40集全免费播放电影演员.| 打开B站看片| 男人吃过女人乳房后会断联吗 | 女生胸前两颗大大的包是什么| 强妾干伦久久久久久久久| 《女学生做爰》| 双乳被四个男人吃奶| 按摩3-4| 人间水蜜桃MAC923| 《女仆教育》动漫第一季| 国产在线观看免费全集电视剧网站 | 校长揉捏陈若雪的奶头| 丈夫不在家儿媳想老公的背景故事| 男按摩师舌头伸进去了SPA漫画| 罗曼史1999| 老师好爽要尿了潮喷了18P| 站立式插插的正确方法| 把腿扒开让我添30分钟| 麻花传MDR国语免费版| 三个老头拥着躁我一晚| 父亲开了两个女儿包演员表| 《交换做爰》在线观看| 中文在线字幕观看电视剧| 美国伦理巜交换做爰| 白天像教授晚上像野兽| 乖再分开点小说免费阅读| 《体热》完整版| 妻子的姐姐免费观看大全电视剧 | 女子排尿视频大全| 国外不堪入目的演唱会| 五姑娘影院在线观看免费版电视剧 | 妈妈3| 肉多到炸的年下小狗(双南)| 三男一女吃奶添下面| 蜜桃成熟了免费观看完整版电视剧| 女人尝试到更粗大的心理变化