python: [Errno 10054] 远程主机强行关闭了现有连接 [英] python: [Errno 10054] An existing connection was forcibly closed by the remote host

查看:66
本文介绍了python: [Errno 10054] 远程主机强行关闭了现有连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写 python 来使用 Twitter-py 抓取 Twitter 空间.我已将爬虫设置为在对 api.twitter.com 的每个请求之间休眠一段时间(2 秒).但是,运行一段时间后(大约 1 次),当 Twitter 的速率限制尚未超过时,我收到此错误.

I am writing python to crawl Twitter space using Twitter-py. I have set the crawler to sleep for a while (2 seconds) between each request to api.twitter.com. However, after some times of running (around 1), when the Twitter's rate limit not exceeded yet, I got this error.

[Errno 10054] An existing connection was forcibly closed by the remote host.

此问题的可能原因是什么以及如何解决?

What are possible causes of this problem and how to solve this?

我搜索了一下,发现可能是推特服务器本身因为请求过多而强制关闭连接.

I have searched through and found that the Twitter server itself may force to close the connection due to many requests.

非常感谢您.

推荐答案

这可能是由于连接的两端在保活期间对连接是否超时存在分歧而导致的.(您的代码尝试在服务器关闭连接时重用该连接,因为它已经空闲太长时间了.)您基本上应该只是通过新连接重试该操作.(我很惊讶您的图书馆不会自动执行此操作.)

This can be caused by the two sides of the connection disagreeing over whether the connection timed out or not during a keepalive. (Your code tries to reused the connection just as the server is closing it because it has been idle for too long.) You should basically just retry the operation over a new connection. (I'm surprised your library doesn't do this automatically.)

这篇关于python: [Errno 10054] 远程主机强行关闭了现有连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆