我正在尝试使用 Juypter Notebook 接收 json 数据的简单 Flask 应用程序:
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def returnMaintenanceNeeded():
content = request.get_json(silent=True, force=True)
json_data = json.dumps(content)
data = json.loads(json_data)
if __name__ == '__main__':
app.run(port=8187, debug=True)
我使用 Postman 发送了一个 POST 请求,起初它工作得很好。然后我想我停止并启动 Jupyter Notebook 的速度太快了,然后我不断收到此错误消息:
Traceback (most recent call last):
File "/usr/local/Caskroom/miniconda/base/envs/leoenv/lib/python3.9/site-packages/ipykernel_launcher.py", line 17, in <module>
app.launch_new_instance()
File "/usr/local/Caskroom/miniconda/base/envs/leoenv/lib/python3.9/site-packages/traitlets/config/application.py", line 991, in launch_instance
app.initialize(argv)
File "/usr/local/Caskroom/miniconda/base/envs/leoenv/lib/python3.9/site-packages/traitlets/config/application.py", line 113, in inner
return method(app, *args, **kwargs)
File "/usr/local/Caskroom/miniconda/base/envs/leoenv/lib/python3.9/site-packages/ipykernel/kernelapp.py", line 665, in initialize
self.init_sockets()
File "/usr/local/Caskroom/miniconda/base/envs/leoenv/lib/python3.9/site-packages/ipykernel/kernelapp.py", line 309, in init_sockets
self.shell_port = self._bind_socket(self.shell_socket, self.shell_port)
File "/usr/local/Caskroom/miniconda/base/envs/leoenv/lib/python3.9/site-packages/ipykernel/kernelapp.py", line 246, in _bind_socket
return self._try_bind_socket(s, port)
File "/usr/local/Caskroom/miniconda/base/envs/leoenv/lib/python3.9/site-packages/ipykernel/kernelapp.py", line 222, in _try_bind_socket
s.bind("tcp://%s:%i" % (self.ip, port))
File "/usr/local/Caskroom/miniconda/base/envs/leoenv/lib/python3.9/site-packages/zmq/sugar/socket.py", line 229, in bind
super().bind(addr)
File "zmq/backend/cython/socket.pyx", line 562, in zmq.backend.cython.socket.Socket.bind
File "zmq/backend/cython/checkrc.pxd", line 28, in zmq.backend.cython.checkrc._check_rc
zmq.error.ZMQError: Address already in use
我已经在互联网上查找了错误消息,但没有任何帮助。我重新启动了我的计算机,我杀死了所有 Python 进程,我停止了所有 Jupyter Notebooks,我从 Jupyter Notebooks 中删除了所有运行时文件,以防任何旧文件干扰当前文件,我更新了 Jupyter & Conda,我使用 JupyterLab 进行了尝试,然后我当然尝试为 Flask Web 服务器提供其他端口(例如 5000、7000、6000、8000、8187,...)
没有任何帮助,我一直收到这个错误。有什么想法吗?
Python版本:3.9.16
操作系统:Mac OS Montery 12.3
烧瓶:2.2.2