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

后端 未结 4 945
失恋的感觉
失恋的感觉 2020-11-29 02:53

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

4条回答
  •  忘掉有多难
    2020-11-29 03:39

    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.)

提交回复
热议问题