I'm making a simple Python script to communicate with a server to get an XML file containing player data like money, weapons owned, xp, etc.
It's too large of a file to send in one packet so it gets chunked. However, when using this while loop:
def parseChunk(chunk):
if "\r\n" in chunk:
return chunk.split("\r\n")[1]
else:
return chunk
while True:
data = ssl_sock.recv(4096).decode()
print(data)
if "\r\n\r\n" in data and start_chunking is False:
start_chunking = True
temp = data.split("\r\n\r\n")[1]
login_resp += temp.split("\r\n")[1]
elif start_chunking:
if data.startswith("0\r\n"):
print("reached the end")
break
login_resp += parseChunk(data)
It prematurely print
's "reached the end" and a good portion of the file is still missing. As far as I know when the server is done sending chunks it sends the "final chunk" which is 0\r\n
which indicates no more data will be sent right? Apparently that's not so. The server also isn't sending a Content-Length
header so I have no idea what amount of bytes to expect.
Any help or insight would be much appreciated. Thanks for your time. If more information is needed please let me know before downvoting. Thanks.