Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

Thank you very much in advance.

like image 696
Nama Keru Avatar asked Jan 11 '12 05:01

Nama Keru


People also ask

Can't start Server Error 10054 An existing connection was forcibly closed by the remote host?

The 10054 error is raised by the Operating System and reports that an existing connection was forcibly closed by the remote host. You should look at the workload on the execution servers at that location and check the Windows event logs for errors or other activity around the time of the failures.

What WinError 10054?

WinError 10054, An existing connection was forcibly closed by the remote host.


2 Answers

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

like image 148
David Schwartz Avatar answered Oct 17 '22 06:10

David Schwartz


there are many causes such as

  • The network link between server and client may be temporarily going down.
  • running out of system resources.
  • sending malformed data.

To examine the problem in detail, you can use Wireshark.

or you can just re-request or re-connect again.

like image 35
sorry back from offline work Avatar answered Oct 17 '22 04:10

sorry back from offline work