Error "ImportError: No module named request" starting Python 3 app in Bluemix

Error "ImportError: No module named request" starting Python 3 app in Bluemix

我正在尝试在 Bluemix 中启动我的 Python 3 应用程序,它一直说它正在尝试启动。

-----> Uploading droplet (32M)

0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 down
0 of 1 instances running, 1 down
0 of 1 instances running, 1 down
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 down
0 of 1 instances running, 1 down
0 of 1 instances running, 1 down
0 of 1 instances running, 1 down
0 of 1 instances running, 1 starting

我还在日志中收到有关无法找到请求的错误。知道我做错了什么吗?

2015-04-17T08:35:50.88-0400 [App/0]   ERR Traceback (most recent call last):
2015-04-17T08:35:50.88-0400 [App/0]   ERR   File "server.py", line 7, in <module>
2015-04-17T08:35:50.88-0400 [App/0]   ERR     from wordnik import *
2015-04-17T08:35:50.88-0400 [App/0]   ERR   File "/app/.heroku/python/lib/python2.7/site-packages/wordnik/swagger.py", line 10, in <module>
2015-04-17T08:35:50.88-0400 [App/0]   ERR     import urllib.request, urllib.error, urllib.parse
2015-04-17T08:35:50.88-0400 [App/0]   ERR ImportError: No module named request
2015-04-17T08:35:50.96-0400 [DEA]     ERR Instance (index 0) failed to start accepting connections

我能够通过显式调出我需要的 Python 版本来解决这个问题。在当前的 buildpack 中,Bluemix 使用 Python 2.7.9.

为了找出要使用的 Python 版本,我在我的应用程序的根目录中创建了一个名为 runtime.txt 的文件。 runtime.txt内容如下:

python-3.4.1

Python 在 Bluemix 上出现类似启动错误的另一个可能原因是缺少 requirements.txt 中的依赖项。 Ryan Baxter 在他的博客 post Deploying A Python App To BlueMix.

中详细说明了这一点

为了完整起见,他继续指出导致难以理解的错误的其他问题,例如 (1) Python buildpack 级别与 Bluemix/Cloud Foundry 不兼容,以及 (2)应用程序无法从环境变量 VCAP_APP_PORT 中检索用于启动 HTTP 服务器的端口。后者的症状是应用程序在本地运行良好,但在部署后崩溃并出现错误 "failed to start accepting connections"。如果您看到此错误并挠头一会儿,请不要难过;几乎每个人 在他们的第一次部署中都会犯这个错误。