以下の問題を長い間修正しようとしてきました.200,401 eycのような応答を得ようとしています.以下のコードを簡単に見ていただければ幸いです.2つの異なる方法で試しましたが、どれも機能しません.ブロック内に示されているように、誰かが私を助けてくれれば本当に感謝しています。
"head="/questions/ask"
host = "stackoverflow.com"
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(1)
try:
sock.connect((host, port))
except socket.error, msg:
sys.stderr.write("[ERROR] %s\n" % msg[1])
sys.exit(2)
sock.send("HEAD %s HTTP/1.0\r\n\r\n")%(head)
#this one gives me error" sock.send("HEAD head1 HTTP/1.0\r\n\r\n")%(head)
TypeError: unsupported operand type(s) for %: 'int' and 'str'", my Url is string!
sock.send("HEAD head HTTP/1.0\r\n\r\n")
#gives error 404
s=sock.recv(12)
print s
sock.close()
sys.exit"