python 发 http请求,服务器会主动断开连接,我写的代码有问题吗
cn=httplib.HTTPConnection('10.100.1.13:8000')data=urllib.urlencode({'user_name':'测试'}...
cn =httplib.HTTPConnection('10.100.1.13:8000')
data = urllib.urlencode({'user_name':'测试'})
cn.request('POST', '/test/',data)
result = cn.getresponse()
resultContent = result.read()
result.close()
cn.close()
这段代码有什么问题,为什么执行第二次,服务器就会报
error: [Errno 10054]
Traceback (most recent call last):
File "C:\Documents and Settings\taohua\桌面\python\test.py", line 21, in <module>
result = conn.getresponse()
File "C:\Python26\lib\httplib.py", line 990, in getresponse
response.begin()
File "C:\Python26\lib\httplib.py", line 420, in begin
self.msg = HTTPMessage(self.fp, 0)
File "C:\Python26\lib\mimetools.py", line 25, in __init__
rfc822.Message.__init__(self, fp, seekable)
File "C:\Python26\lib\rfc822.py", line 108, in __init__
self.readheaders()
File "C:\Python26\lib\httplib.py", line 276, in readheaders
line = self.fp.readline()
File "C:\Python26\lib\socket.py", line 427, in readline
data = recv(1)
error: [Errno 10054]
没有占用哦,我用的是8000端口
防火墙被关掉了哦
这是http头
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"} 展开
data = urllib.urlencode({'user_name':'测试'})
cn.request('POST', '/test/',data)
result = cn.getresponse()
resultContent = result.read()
result.close()
cn.close()
这段代码有什么问题,为什么执行第二次,服务器就会报
error: [Errno 10054]
Traceback (most recent call last):
File "C:\Documents and Settings\taohua\桌面\python\test.py", line 21, in <module>
result = conn.getresponse()
File "C:\Python26\lib\httplib.py", line 990, in getresponse
response.begin()
File "C:\Python26\lib\httplib.py", line 420, in begin
self.msg = HTTPMessage(self.fp, 0)
File "C:\Python26\lib\mimetools.py", line 25, in __init__
rfc822.Message.__init__(self, fp, seekable)
File "C:\Python26\lib\rfc822.py", line 108, in __init__
self.readheaders()
File "C:\Python26\lib\httplib.py", line 276, in readheaders
line = self.fp.readline()
File "C:\Python26\lib\socket.py", line 427, in readline
data = recv(1)
error: [Errno 10054]
没有占用哦,我用的是8000端口
防火墙被关掉了哦
这是http头
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"} 展开
展开全部
因为访问过于频繁
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
加个header呢?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询