Answer the question
In order to leave comments, you need to log in
How to decode string received from server?
def send_request(connection):
data = connection.recv(1024).decode('utf-8')
get_request = data.split('GET /')[1].split('HTTP/')[0].strip()
try:
price = int(get_request)
except ValueError:
content = b'Error'
else:
content = str(Algorithm(products_base, rating_base).build(price)).encode('utf-8')
connection.send(b'HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n')
connection.send(content)
if __name__ == '__main__':
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('127.99.83.100', 2000))
server.listen(1)
while True:
connection, address = server.accept()
connection_thread = threading.Thread(target=send_request, args=(connection,))
connection_thread.start()
Answer the question
In order to leave comments, you need to log in
Perhaps the browser just chooses the wrong encoding. You can simply manually select the page you need for this page through the menu to make sure of this. You can also add encoding to Content-Type:
Content-Type: text/html; charset=utf-8
Try it. Import the demjson module
import demjson
demjson.decode( ваш json )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question