Program Runs but can't format the data
Program Runs but can't format the data
(OP)
I'm new to this Python program so I'm experimenting and fighting with syntax and formatting.
I've managed to figure out how to make this program execute and stay running but I can't figure out how to eliminate extra characters in the received data.
When I run it, I get b'GET /8005551212&230' as a response. So how do I strip off the b'GET / and the ' on the end to end up with an editable string like 8005551212&230 or ulimately two strings of 8005551212 and 230 that I can then format into whatever arrangement of extra info that I may add? It gives an error when I leave the line that attempts to convert it to a string and strip off the extra characters: it gives me: TypeError: a bytes-like object is required, not 'str'
[code]
import socket, sys
host = ''
port = 65432
socksize = 19
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
print("Server started on port: %s" % port)
s.listen(1)
print("Now listening...n")
while True:
conn, addr = s.accept()
data = conn.recv(socksize)
string = data.strip('/') #this line doesn't work
if not data: #it gives me: TypeError: a bytes-like object is required, not 'str'
x=1
else:
print(data)
print(string)
I've managed to figure out how to make this program execute and stay running but I can't figure out how to eliminate extra characters in the received data.
When I run it, I get b'GET /8005551212&230' as a response. So how do I strip off the b'GET / and the ' on the end to end up with an editable string like 8005551212&230 or ulimately two strings of 8005551212 and 230 that I can then format into whatever arrangement of extra info that I may add? It gives an error when I leave the line that attempts to convert it to a string and strip off the extra characters: it gives me: TypeError: a bytes-like object is required, not 'str'
[code]
import socket, sys
host = ''
port = 65432
socksize = 19
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
print("Server started on port: %s" % port)
s.listen(1)
print("Now listening...n")
while True:
conn, addr = s.accept()
data = conn.recv(socksize)
string = data.strip('/') #this line doesn't work
if not data: #it gives me: TypeError: a bytes-like object is required, not 'str'
x=1
else:
print(data)
print(string)
RE: Program Runs but can't format the data
example:
CODE