I made an HTTP server using python socket, and it works perfectly except for a few files. These select files show up empty on the browser, but not empty when sent from the server. My debugging had gotten to the point where I’m downloading wireshark to check network traffic, but I wanted to ask here in case anyone has any answers. (I have been reading stack overflow for years, and I thought I might as well give it a try)
I looked at the code, and it doesn’t have any bias for the empty files, and I have successfully printed the file content right before using the sendall() function to send to the browser.
Here’s a snippet of code directly involved where in the bug. d & r are the filenames (d has no slash while r does eg. “index.html” or “/index.html”)
` elif d[-5:]=='.html':
c.sendall('''HTTP/1.1 200 OKn'''.encode())
f=open(os.getcwd()+r)
o=f.read()
f.close()
print("nSending:",os.getcwd()+r,"n")
c.sendall(o.encode())`python
Neurosis Sage is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.