socket.gaierror:[Errno -2]名称或服务未知 [英] socket.gaierror: [Errno -2] Name or service not known
本文介绍了socket.gaierror:[Errno -2]名称或服务未知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是套接字编程的新手 下面的程序是一个客户端程序,它从服务器请求文件,但是我收到如下所示的错误. 我的输入是GET index.html,代码是 谁能解决这个错误...?
Guys i'm a newbie to the socket programming Following program is a client program which request a file from the server,But i'm getting the error as show below.. My input is GET index.html and the code is Can anyone solve this error...?
#!/usr/bin/env python
import httplib
import sys
http_server = sys.argv[0]
conn = httplib.HTTPConnection(http_server)
while 1:
cmd = raw_input('input command (ex. GET index.html): ')
cmd = cmd.split()
if cmd[0] == 'exit':
break
conn.request(cmd[0],cmd[1])
rsp = conn.getresponse()
print(rsp.status, rsp.reason)
data_received = rsp.read()
print(data_received)
conn.close()
input command (ex. GET index.html): GET index.html
Traceback (most recent call last):
File "./client1.py", line 19, in <module>
conn.request(cmd[0],cmd[1])
File "/usr/lib/python2.6/httplib.py", line 910, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python2.6/httplib.py", line 947, in _send_request
self.endheaders()
File "/usr/lib/python2.6/httplib.py", line 904, in endheaders
self._send_output()
File "/usr/lib/python2.6/httplib.py", line 776, in _send_output
self.send(msg)
File "/usr/lib/python2.6/httplib.py", line 735, in send
self.connect()
File "/usr/lib/python2.6/httplib.py", line 716, in connect
self.timeout)
File "/usr/lib/python2.6/socket.py", line 500, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known
推荐答案
sys.argv [0]不是您想的那样. sys.argv [0]是程序或脚本的名称.脚本的第一个参数是sys.argv [1].
sys.argv[0] is not what you think it is. sys.argv[0] is the name of the program or script. The script's first argument is sys.argv[1].
这篇关于socket.gaierror:[Errno -2]名称或服务未知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文