Reputation: 81
I'm trying to make a proof of concept tcp server and client with Python 3.4. Everything with network part works nice. I tried to make it interactive and get user input from the client and send it to the server. But when I try to use it as HTTP client (write a custom request in console and send it to the server) it failed to get a response. The problem is that input() function interprets \r\n\ as string. How can I tell to python to interpret them as a .
Example :
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("www.google.com", 80))
user_input = input("Inser message: ") # GET / HTTP/1.1\r\n\r\n
sock.sendall(user_input.encode("utf-8"))
message = sock.recv(4096)
Thanks in advance for any suggestion.
Upvotes: 1
Views: 74
Reputation: 42778
You can use replace:
user_input = user_input.replace('\\r', '\r').replace('\\n', '\n')
Upvotes: 2