重复的POST请求导致错误"socket.error:(99,'无法分配请求的地址')". [英] Repeated POST request is causing error "socket.error: (99, 'Cannot assign requested address')"
问题描述
我的盒子中部署了一个Web服务.我想通过各种输入来检查该服务的结果.这是我正在使用的代码:
I have a web-service deployed in my box. I want to check the result of this service with various input. Here is the code I am using:
import sys
import httplib
import urllib
apUrl = "someUrl:somePort"
fileName = sys.argv[1]
conn = httplib.HTTPConnection(apUrl)
titlesFile = open(fileName, 'r')
try:
for title in titlesFile:
title = title.strip()
params = urllib.urlencode({'search': 'abcd', 'text': title})
conn.request("POST", "/somePath/", params)
response = conn.getresponse()
data = response.read().strip()
print data+"\t"+title
conn.close()
finally:
titlesFile.close()
在打印相同数量的行后,此代码给出错误(28233).错误消息:
This code is giving an error after same number of lines printed (28233). Error message:
Traceback (most recent call last):
File "testService.py", line 19, in ?
conn.request("POST", "/somePath/", params)
File "/usr/lib/python2.4/httplib.py", line 810, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python2.4/httplib.py", line 833, in _send_request
self.endheaders()
File "/usr/lib/python2.4/httplib.py", line 804, in endheaders
self._send_output()
File "/usr/lib/python2.4/httplib.py", line 685, in _send_output
self.send(msg)
File "/usr/lib/python2.4/httplib.py", line 652, in send
self.connect()
File "/usr/lib/python2.4/httplib.py", line 636, in connect
raise socket.error, msg
socket.error: (99, 'Cannot assign requested address')
我正在使用Python 2.4.3.我也在做conn.close()
.但是为什么会出现此错误?
I am using Python 2.4.3. I am doing conn.close()
also. But why is this error being given?
推荐答案
这不是python问题.
This is not a python problem.
在Linux内核2.4中,临时端口范围是从32768到61000.因此可用端口数= 61000-32768 + 1 =28233.据我了解,因为所讨论的Web服务非常快(<5ms)实际上),因此所有端口都被耗尽.该程序必须等待一两分钟左右才能关闭端口.
In linux kernel 2.4 the ephemeral port range is from 32768 through 61000. So number of available ports = 61000-32768+1 = 28233. From what i understood, because the web-service in question is quite fast (<5ms actually) thus all the ports get used up. The program has to wait for about a minute or two for the ports to close.
我所做的是计算conn.close()
的数量.当数字为28000时,请等待90秒,然后重置计数器.
What I did was to count the number of conn.close()
. When the number was 28000 wait for 90sec and reset the counter.
这篇关于重复的POST请求导致错误"socket.error:(99,'无法分配请求的地址')".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!