[英]python3.8 http.server - ConnectionResetError: [Errno 104] Connection reset by peer
I've set up a simple http server to share some files with a friend.我设置了一个简单的 http 服务器与朋友共享一些文件。 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.其中
carmine
是一个包含文件的目录。
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:我可以通过
localhost:2339
访问文件,我的朋友可以下载文件并且他们这边没有报告错误,但我的日志显示:
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.
发生这种情况的原因有很多:您取消了文件下载,有人杀死了访问您的 http 服务器的程序,或者大文件导致客户端在下载时超时,等等。
Right now you're using the default SimpleHTTPRequestHandler
.现在您正在使用默认的
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.如果您想知道是什么导致了错误并且想要,您可以创建它的子类并编写一些日志记录函数,这些函数会告诉您以下内容:1. IP 正在访问您的服务器,2. 请求参数,3. 它们是什么文件'正在尝试下载等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.