重复的 POST 请求导致错误“socket.error: (99, 'Cannot assign requested address')"

Repeated POST request is causing error quot;socket.error: (99, #39;Cannot assign requested address#39;)quot;(重复的 POST 请求导致错误“socket.error: (99, Cannot assign requested address))
本文介绍了重复的 POST 请求导致错误“socket.error: (99, 'Cannot assign requested address')"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的盒子里部署了一个网络服务.我想通过各种输入检查此服务的结果.这是我正在使用的代码:

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+"	"+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, 'Cannot assign requested address')"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Leetcode 234: Palindrome LinkedList(Leetcode 234:回文链接列表)
How do I read an Excel file directly from Dropbox#39;s API using pandas.read_excel()?(如何使用PANDAS.READ_EXCEL()直接从Dropbox的API读取Excel文件?)
subprocess.Popen tries to write to nonexistent pipe(子进程。打开尝试写入不存在的管道)
I want to realize Popen-code from Windows to Linux:(我想实现从Windows到Linux的POpen-code:)
Reading stdout from a subprocess in real time(实时读取子进程中的标准输出)
How to call type safely on a random file in Python?(如何在Python中安全地调用随机文件上的类型?)