如何解决10054错误 [英] How to solve the 10054 error

查看:1167
本文介绍了如何解决10054错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用某个网站提供的应用,以定期(例如30秒)从该网站收集一些数据。
然后将返回的响应记录在数据库中。

I'm using an app provided by some website to collect some data from the website periodly, say, 30s a time. The returned response is then recorded in database.

我使用导入请求对请求进行模块化,并编写代码以捕获Exception。
主要功能的代码如下:

I use the requests modular by import requests and write codes to catch Exception. The codes for the main function are as following:

def get_response(self):
    try:
       response = requests.get(self.request_url)
       if response.status_code == 200:
          return response.json()
       except Exception as e:
          msg = "Exception is:\n %s \n" % e
          print msg

以上功能在开始的几个小时内效果很好。
该函数还可以从某些异常中恢复,例如:
(连接中止。,BadStatusLine('',))


(连接中止 。',error(10053,''))
它忽略了异常(通过在数据库中记录一个Null)并继续获得下一个周期的响应。

The above function works quite well for the first several hours. The function can also recover from some exceptions like: ('Connection aborted.', BadStatusLine("''",))
or ('Connection aborted.', error(10053, '')) It omits the exception (by recording a Null in database) and continues to get the response of next period.

但是,当遇到10054错误时,该函数将停止工作。

However, the function stops working when encoutering a 10054 error.

Exception is:
 ('Connection aborted.', error(10054, '')) 

我检查数据库以查找所有响应在出现10054错误之后为空。
我首先猜想该网站可能会崩溃,因此未收到任何回复。
但是,当我手动重新启动该功能时,它再次开始获得响应。
因此,无法实现该网站的崩溃。

I check the database to find that all the response is Null after the time that the 10054 error comes. I firstly guess that the website may breakdown, thus no response is received. But when I manually restart the function, it starts to get response again. So that's no realated with breakdown of the website.

我在stackoverflow中搜索并找到:Errno 10054远程主机强行关闭了现有连接。
但是我不知道如何解决它。

I search in stackoverflow and find: Errno 10054 An existing connection was forcibly closed by the remote host. But I don't know how to resolve it.

请问您对这个问题有什么看法?(理想情况下)
还是提供一些无需手动重新启动功能的解决方案?
(看起来,一旦我重新启动该功能,它又可以正常工作。)

Could you please provide some solotion to this problem?(ideally speaking) or provide some solution to restart the function without manually restarting? (It looks like once I restart the funtion and it works again.)

预先感谢。

推荐答案

Web服务器主动拒绝了您的连接。通常是因为它拥塞,速率受限或认为您正在发起拒绝服务攻击。如果您是从服务器上获得的,则应在重新尝试之前睡一会儿。实际上,如果您在重试前没有入睡,则可能是拒绝服务攻击。有礼貌的做法是实现(1,2,4,8,16,32)秒的渐进式睡眠。

The web server actively rejected your connection. That's usually because it is congested, has rate limiting or thinks that you are launching a denial of service attack. If you get this from a server, you should sleep a bit before trying again. In fact, if you don't sleep before retry, you are a denial of service attack. The polite thing to do is implement a progressive sleep of, say, (1,2,4,8,16,32) seconds.

这篇关于如何解决10054错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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