+ 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

14th Sep 2021, 7:42 AM
Julian
Julian - avatar
6 odpowiedzi
+ 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)
19th Sep 2021, 8:01 AM
Abhay
Abhay - avatar
+ 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.
14th Sep 2021, 8:28 AM
Abhay
Abhay - avatar
+ 2
Thank you for your help, Abhay it works now.
29th Sep 2021, 6:34 AM
Julian
Julian - avatar
+ 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
19th Sep 2021, 2:24 AM
Julian
Julian - avatar
+ 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
2nd Oct 2021, 3:10 PM
Tech
+ 1
Tech yes that is probably python2 . If you write "print something" In python 3 it gives an error. About the error it clearly says it needs bytes like object but we are passing it a string instead.
2nd Oct 2021, 8:17 PM
Abhay
Abhay - avatar