python-3.x 使用ngrok部署flask应用程序时,索引出错误

jum4pzuy  于 2023-05-19  发布在  Python
关注(0)|答案(2)|浏览(167)

我已经使用Flask创建了一个服务器来演示我的ML模型。我在Google Colab上运行它,并使用flask-ngrok进行隧道。它正常工作,但突然停止工作,并显示此错误:

=> loading checkpoint './semi_supervised_model_3/ckpt_epoch_10.00.pth'
=> loaded checkpoint './semi_supervised_model_3/ckpt_epoch_10.00.pth' (epoch 10.0)
 * Serving Flask app "demo_Server" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 1182, in run
    self.function(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/dist-packages/flask_ngrok.py", line 70, in start_ngrok
    ngrok_address = _run_ngrok()
  File "/usr/local/lib/python3.6/dist-packages/flask_ngrok.py", line 38, in _run_ngrok
    tunnel_url = j['tunnels'][0]['public_url']  # Do the parsing of the get
IndexError: list index out of range

这个错误是什么意思?为什么我什么都没改变它就来了?

vfwfrxfs

vfwfrxfs1#

当我终止当前会话时,我的问题得到了解决。在新的会话中,我重新安装了flask-ngrok,它工作得很好。

nmpmafwu

nmpmafwu2#

这是因为小的延迟,程序无法在随后的代码行中检索公共URL。当你的互联网连接不够快时,这个小的延迟可能不够。
尝试增加flask_ngrok.py文件中的time.sleep in _run_ngrok()方法,该文件在安装时包含在python3.6/site-packages中。

相关问题