Ich habe dieses Programm, aber es sagt mir den Fehler auf dem Titel, ich glaube, ich habe etwas setzen für utf-8, gelten aber ich weiß nicht, wo oder wieWie kann ich TypeError lösen: ein Byte-ähnliches Objekt wird benötigt, nicht 'str'?
#!/usr/bin/python3
import socket
status = 0
mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mySocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
mySocket.bind(('localhost', 1234))
mySocket.listen(5)
while True:
print('Waiting for connections')
(recvSocket, address) = mySocket.accept()
print('HTTP request received:')
print(recvSocket.recv(1024))
request = recvSocket.recv(1024)
slot = request.split(' ')
try:
num = int(slot[1][1:])
except ValueError:
msg = ("Asegurese que su URL contiene un numero al final. Ejemplo: localhost:1234/56")
recvSocket.send("HTTP/1.1 200 OK\r\n\r\n" + "<html><body>" + msg + "</body></html>" + "\r\n")
status = 0
Mögliches Duplikat von [TypeError: ein Byte-ähnliches Objekt wird benötigt, nicht 'str'] (http://stackoverflow.com/questions/35777639/typeerror-a-bytes-like-object-is-required-not -str) – Idos