在 localhost 中运行 Flask 脚本时,我尝试从同一本地网络中的另一台设备访问网页。虽然我可以查看网页,但我经常注意到这个错误突然弹出,在我的控制台中我的 IP 附近出现随机数,导致 OSError 并拒绝我以后对 Flask 服务器的请求。
Exception happened during processing of request from ('192.168.0.4', 41252)
Exception happened during processing of request from ('192.168.0.4', 41250)
Traceback (most recent call last):
Traceback (most recent call last):
File "C:\Program Files\Python38\lib\socketserver.py", line 650, in process_request_thread
self.finish_request(request, client_address)
File "C:\Program Files\Python38\lib\socketserver.py", line 650, in process_request_thread
self.finish_request(request, client_address)
File "C:\Program Files\Python38\lib\socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Program Files\Python38\lib\socketserver.py", line 720, in __init__
self.handle()
File "C:\Program Files\Python38\lib\socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\me\AppData\Roaming\Python\Python38\site-packages\werkzeug\serving.py", line 329, in handle
rv = BaseHTTPRequestHandler.handle(self)
File "C:\Program Files\Python38\lib\socketserver.py", line 720, in __init__
self.handle()
File "C:\Program Files\Python38\lib\http\server.py", line 426, in handle
self.handle_one_request()
File "C:\Users\me\AppData\Roaming\Python\Python38\site-packages\werkzeug\serving.py", line 329, in handle
rv = BaseHTTPRequestHandler.handle(self)
File "C:\Program Files\Python38\lib\http\server.py", line 426, in handle
self.handle_one_request()
File "C:\Users\me\AppData\Roaming\Python\Python38\site-packages\werkzeug\serving.py", line 360, in handle_one_request
self.raw_requestline = self.rfile.readline()
File "C:\Program Files\Python38\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
File "C:\Users\me\AppData\Roaming\Python\Python38\site-packages\werkzeug\serving.py", line 360, in handle_one_request
self.raw_requestline = self.rfile.readline()
File "C:\Program Files\Python38\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
OSError: [WinError 10022] An invalid argument was supplied
OSError: [WinError 10022] An invalid argument was supplied
----------------------------------------
----------------------------------------
Exception happened during processing of request from ('192.168.0.4', 41378)
Exception happened during processing of request from ('192.168.0.4', 41380)
Traceback (most recent call last):
Traceback (most recent call last):
File "C:\Program Files\Python38\lib\socketserver.py", line 650, in process_request_thread
self.finish_request(request, client_address)
File "C:\Program Files\Python38\lib\socketserver.py", line 650, in process_request_thread
self.finish_request(request, client_address)
File "C:\Program Files\Python38\lib\socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Program Files\Python38\lib\socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Program Files\Python38\lib\socketserver.py", line 720, in __init__
self.handle()
File "C:\Program Files\Python38\lib\socketserver.py", line 720, in __init__
self.handle()
File "C:\Users\me\AppData\Roaming\Python\Python38\site-packages\werkzeug\serving.py", line 329, in handle
rv = BaseHTTPRequestHandler.handle(self)
File "C:\Users\me\AppData\Roaming\Python\Python38\site-packages\werkzeug\serving.py", line 329, in handle
rv = BaseHTTPRequestHandler.handle(self)
File "C:\Program Files\Python38\lib\http\server.py", line 426, in handle
self.handle_one_request()
File "C:\Users\me\AppData\Roaming\Python\Python38\site-packages\werkzeug\serving.py", line 360, in handle_one_request
self.raw_requestline = self.rfile.readline()
File "C:\Program Files\Python38\lib\http\server.py", line 426, in handle
self.handle_one_request()
File "C:\Users\me\AppData\Roaming\Python\Python38\site-packages\werkzeug\serving.py", line 360, in handle_one_request
self.raw_requestline = self.rfile.readline()
File "C:\Program Files\Python38\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
File "C:\Program Files\Python38\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
OSError: [WinError 10022] An invalid argument was supplied
OSError: [WinError 10022] An invalid argument was supplied
----------------------------------------
----------------------------------------
据我所知,我对错误中的套接字或其他东西一无所知。在我只是将 HTML 模板渲染为响应之后,如何阻止此类错误的发生?
编辑 :
我在这里添加了我的 Flask 脚本的一部分,我仍然从中得到错误。当我尝试从网络中连接的其他设备访问我的网页时,再次出现错误
from flask import *
app = Flask(__name__)
@app.route('/')
def index():
return render_template("home.html")
@app.route('/download')
def downloads():
return render_template("downloads.html")
if __name__ == '__main__':
app.run(host="0.0.0.0", port=5000 , debug = True)
这次我也得到了类似的错误如下
----------------------------------------
Exception happened during processing of request from ('192.168.0.5', 42834)
Traceback (most recent call last):
File "C:\Program Files\Python38\lib\socketserver.py", line 650, in process_request_thread
self.finish_request(request, client_address)
File "C:\Program Files\Python38\lib\socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Program Files\Python38\lib\socketserver.py", line 720, in __init__
self.handle()
File "C:\Users\me\AppData\Roaming\Python\Python38\site-packages\werkzeug\serving.py", line 329, in handle
rv = BaseHTTPRequestHandler.handle(self)
File "C:\Program Files\Python38\lib\http\server.py", line 426, in handle
self.handle_one_request()
File "C:\Users\me\AppData\Roaming\Python\Python38\site-packages\werkzeug\serving.py", line 360, in handle_one_request
self.raw_requestline = self.rfile.readline()
File "C:\Program Files\Python38\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
OSError: [WinError 10022] An invalid argument was supplied
----------------------------------------