【问题标题】:python3.8 http.server - ConnectionResetError: [Errno 104] Connection reset by peerpython3.8 http.server - ConnectionResetError:[Errno 104]对等方重置连接
【发布时间】:2021-03-07 05:23:12
【问题描述】:

我设置了一个简单的 http 服务器来与朋友共享一些文件。我知道还有其他共享文件的方式,但我有兴趣这样做并解决提出的问题。

服务器端代码很简单:

 #!/bin/bash
 /usr/bin/python3 -u -m http.server -d /srv/carmine 2339

其中carmine 是一个包含文件的目录。

我可以通过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
   

这里发生了什么?我需要设置一些服务器端参数吗?

【问题讨论】:

    标签: python http


    【解决方案1】:

    此消息表示连接的另一端在您的服务器上“挂断”。发生这种情况的原因有很多:您取消了文件下载,有人杀死了访问您的 http 服务器的程序,或者大文件导致客户端在下载时超时等等。

    现在您使用的是默认的SimpleHTTPRequestHandler。如果您对导致错误的原因感到好奇并且想要,您可以创建它的子类并编写一些日志记录函数,这些函数会告诉您以下内容:1. 什么 IP 正在访问您的服务器,2. 请求参数,3. 他们是什么文件'正在尝试下载等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-03
      • 2016-10-10
      • 2018-05-22
      • 2014-01-04
      • 2021-08-27
      相关资源
      最近更新 更多