T'es pas trop vieux pour télétubbies ?!
Merci, ça marche!
Merci, ça marche!
import socket s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('localhost', 80)) s.send("GET /index.html\r\n\r\n") d = s.recv(2048) print d s.close()
% python2.7 pysc.py
% python3.7 pysc.py File "pysc.py", line 6 print d ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(d)?
% python3.7 pysc.py Traceback (most recent call last): File "pysc.py", line 4, in <module> s.send("GET /index.html\r\n\r\n") TypeError: a bytes-like object is required, not 'str'
import socket s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('localhost', 80)) s.send("GET /index.html\r\n\r\n".encoding('utf-8')) d = s.recv(2048) print (d)
Commentaire