Skip to content
Advertisement

Python client socket can’t receive data from a successful response

Socket can’t receive any data from the server, when there is a successful response, but with bad requests it can. Also server responds, just the socket can’t receive data (checked in WireShark)

JavaScript

Advertisement

Answer

First, the HTTP GET expects a sequence of CR LF characters after each header line not just a single ‘n’ character and an extra CR LF after the last header line. Also, the join() adds the separator between each pair but not at the end so must append data with CR LF + CR LF to be a valid HTTP request.

Second, the 'Host: {HOST}' must be a f-string otherwise the “{HOST}” is not replaced.

JavaScript

Output:

JavaScript

If the HTTP response is larger than 4096 bytes then you would need to call ssock.recv() in a loop until it returns a byte array of length 0.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement