+ 1
Python TCP client - error invalid character
Dear Community In my TCP Client program I have the following error. Please, I don't know how to solve it. What exactly is wrong? Thank you all for help. https://code.sololearn.com/cS6ujj3ARGT7/?ref=app
6 ответов
+ 2
Swissrobin no indentation needed in your code.
Correct code after re inserting the space and removing indentation.
import socket
target_host = "www.google.com"
target_port = 8
# Create Socket-Object
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# create client connection
client.connect((target_host,target_port))
# Einige Daten senden
client.send("GET / HTTP/1.1\r\nHost: google.com\r\n\r\n")
# get some data
response = client.recv(4096)
print(response)
+ 3
Remove all the spaces and insert them back . The invalid character is probably because you copied the code from somewhere which inserted some of it's native character that can't be understood by sololearn code playground.
+ 2
Thank you for your help, Abhay it works now.
+ 1
Abhay thanks for your answer. I actually work with visual studio code. I tried your solution but the spaces (tabs) are correct. Do you have another idea?
https://www.sololearn.com/post/1290472/?ref=app
+ 1
Abhay I currently have the same problem. But when I run your code, there is an error:
Traceback (most recent call last):
File "/home/peter/hacking/tcpclient.py", line 14, in <module>
client.send("GET / HTTP/1.1\r\nHost: google.com\r\n\r\n")
TypeError: a bytes-like object is required, not 'str'
Can someone help?
I use to read a hacking guide from 2015. Maybe such Code, also as the following is written in Python 2?
https://www.sololearn.com/post/1308993/?ref=app
This is the Code in the book:
https://www.sololearn.com/post/1308995/?ref=app