I've set up a simple http server to share some files with a friend. I know there are other ways of sharing files, but I'm interested in doing it this way and solving the issues raised.
The server side code is simple :
#!/bin/bash
/usr/bin/python3 -u -m http.server -d /srv/carmine 2339
where carmine is a directory containing files.
I can access files through localhost:2339 and my friend can download files and reports no error on their side, but my logs show this:
Exception happened during processing of request from ('xxxxxxxxx', 55664)
Traceback (most recent call last):
File "/usr/lib/python3.8/socketserver.py", line 650, in process_request_thread
self.finish_request(request, client_address)
File "/usr/lib/python3.8/socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python3.8/http/server.py", line 647, in __init__
super().__init__(*args, **kwargs)
File "/usr/lib/python3.8/socketserver.py", line 720, in __init__
self.handle()
File "/usr/lib/python3.8/http/server.py", line 427, in handle
self.handle_one_request()
File "/usr/lib/python3.8/http/server.py", line 415, in handle_one_request
method()
File "/usr/lib/python3.8/http/server.py", line 654, in do_GET
self.copyfile(f, self.wfile)
File "/usr/lib/python3.8/http/server.py", line 853, in copyfile
shutil.copyfileobj(source, outputfile)
File "/usr/lib/python3.8/shutil.py", line 205, in copyfileobj
fdst_write(buf)
File "/usr/lib/python3.8/socketserver.py", line 799, in write
self._sock.sendall(b)
ConnectionResetError: [Errno 104] Connection reset by peer
What is happening here? Do I need to set some server side parameters?
This message means that the other side of the connection "hung up" on your server. This could have happened for a number of reasons: you canceled a file download, someone killed a program accessing your http server, or a large file caused a client timeout while downloading, among other things.
Right now you're using the default SimpleHTTPRequestHandler. If you're curious what caused the error and wanted to, you could create a subclass of it and write some logging functions that would tell you things like 1. what IP is accessing your server, 2. request parameters, 3. what file they're attempting to download, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With