'连接中止.',Python 中的错误(99,'无法分配请求的地址')错误 [英] 'Connection aborted.', error(99, 'Cannot assign requested address') error in Python
问题描述
我查过了,socket.error:[errno 99] 无法分配python中请求的地址和命名空间
重复POST 请求导致错误socket.error: (99, '无法分配请求的地址')"
但没有一个问题给出了预期的答案,以防万一我的问题.我有以下代码片段:
but none of the questions gives an expected answer in case my problem. I have the following code snippet:
with requests.Session() as session:
js_response = session.get(url).json()
- 注意:我尝试使用 urllib2,并且也仅使用 request.get() !我试图重复查询 url,并且每次都期望一个 JSON 对象.但是,在完成一些请求后,我开始收到错误 99(标记如下).这不是一个连续的过程.错误不断出现.我知道发生错误是因为我的请求端口用完了,Linux 内核无法为传出请求分配更多端口,因此引发错误.
错误:
('Connection aborted.', error(99, 'Cannot assign requested address'))
任何人都可以在 Python 中给我建议一种方法,这将帮助我重复请求 URL,而不会出现上述错误.
Could anyone kindly suggest me a way in Python, which will help me to request the URL repeatedly, without getting the aforementioned error.
推荐答案
我遇到这个问题的原因是,Linux 中默认可用的临时端口数量有限.此外,由于 TCP 的工作方式,端口一旦其早期所有者释放控制权,就不容易可用.在将端口号分配给其他进程之前,它会等待一段时间.
The reason that I was getting this issue was that, the number of ephemeral ports that are available by default in Linux are limited. Additionally, the ports are not readily made available once their earlier owner releases the control, because of the way TCP is designed to work. It waits for some time before allocating the port number to some other process.
所以,确切的情况是,我的 Python 脚本尝试使用所有可用端口并在使用后继续释放它们,但根据 TCP 实现,该端口不会立即可供其他进程使用/其他请求,因此我看到了错误消息.
So, what happens exactly is that, my Python script, tries to use all the available ports and goes on releasing them after use, but as per the TCP implementation, the port is not immediately available for use by some other process/ other request, and thus I see the error message.
有关此问题的更多信息可在我的另一个问题中找到,以及在 Unix 和 Linux StackExachange 论坛上的回复:https://unix.stackexchange.com/questions/211647/how-safe-is-it-to-change-the-linux-ephemeral-port-range
More about this is available at my other question, and its responses on the Unix and Linux StackExachange forum: https://unix.stackexchange.com/questions/211647/how-safe-is-it-to-change-the-linux-ephemeral-port-range
这篇关于'连接中止.',Python 中的错误(99,'无法分配请求的地址')错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!