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

查看:42
本文介绍了如何解决 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.

我通过导入请求使用请求模块并编写代码来捕获异常.main函数的代码如下:

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:
 %s 
" % 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错误到来之后所有的响应都是Null.我首先猜测该网站可能会崩溃,因此没有收到任何回复.但是当我手动重新启动该功能时,它又开始得到响应.所以这与网站故障无关.

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 An现有连接被远程主机强行关闭.但是不知道怎么解决.

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天全站免登陆