我是套接字編程的新手,有人可以告訴我什麼是錯誤的,我在這裏做。我得到這個錯誤。我沒有把它定義爲一個函數。當我從main調用它時,它給了我這個錯誤。有人請幫忙!錯誤:[Errno 10054]一個現有的連接被遠程主機強制關閉
#!/usr/bin/env python
import socket
import sys
import urlparse
from urlparse import urlparse
def main(url):
t=url
o = urlparse(t)
x=".".join(o.netloc.split(".")[-2:])
head1= o.path
host = o.netloc
port = 80
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error, msg:
sys.stderr.write("[ERROR] %s\n" % msg[1])
sys.exit()
try:
sock.connect((host, port))
except socket.error, msg:
sys.stderr.write("[ERROR] %s\n" % msg[1])
sys.exit()
try:
sock.send("HEAD %s HTTP/1.0\r\n\r\n" % head1)
except sock.error:
sys.exit()
s=sock.recv(600)
sock.shutdown()
import sys
sys.exit
sock.close()
return s
x=main("www.google.ca")
print x
ERROR I get:
Traceback (most recent call last):
File "C:/myserver/cgi-bin/domainsockettest.py", line 47, in <module>
x=main("www.google.ca")
File "C:/myserver/cgi-bin/domainsockettest.py", line 40, in main
s=sock.recv(600)
error: [Errno 10054] An existing connection was forcibly closed by the remote host
什麼在地球上做'當我不調用它定義爲一個函數'是什麼意思? – EJP