运行Flask脚本时如何修复OSError

时间:2020-06-04 08:18:49

标签: python python-3.x flask oserror

在本地主机上运行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
----------------------------------------

0 个答案:

没有答案