【问题标题】:Using ReportLab with Google App Engine (Python) - works locally but fails when deployed将 ReportLab 与 Google App Engine (Python) 一起使用 - 在本地工作,但在部署时失败
【发布时间】:2014-06-26 22:08:21
【问题描述】:

我成功部署了一个 Google App Engine (Python) 应用程序,并且我已经部署了多个版本,没有出现任何问题。我在本地开发的最新版本现在使用 ReportLab 生成 PDF 下载。这在本地运行良好,但是现在我尝试部署最新版本,我在日志中收到 500 错误:

Traceback (most recent call last):
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 239, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 298, in _LoadHandler
handler, path, err = LoadObject(self._handler)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 84, in LoadObject
obj = __import__(path[0])
  File "/base/data/home/apps/s~tools/2-0.376834985709780158/main.py", line 12, in <module>
    import pdftools
  File "/base/data/home/apps/s~tools/2-0.376834985709780158/pdftools.py", line 1, in <module>
from reportlab.pdfgen import canvas
  File "/base/data/home/apps/s~tools/2-0.376834985709780158/reportlab/pdfgen/canvas.py", line 19, in <module>
from reportlab import rl_config
  File "/base/data/home/apps/s~tools/2-0.376834985709780158/reportlab/rl_config.py", line 122, in <module>
_startUp()
  File "/base/data/home/apps/s~tools/2-0.376834985709780158/reportlab/rl_config.py", line 92, in _startUp
if '~' in d: d = os.path.expanduser(d)
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/posixpath.py", line 268, in expanduser
    import pwd
ImportError: No module named pwd

我只是想知道是否有人可以解释为什么现在部署它不起作用?

【问题讨论】:

  • 由于某种原因,reportlab 正在尝试导入 `pwd — 密码数据库`,这在 appengine 上不受支持/没有意义。您应该查看如何配置 reportlab 以在 appengine 上使用。由于某种原因,路径中使用了“~”。你需要弄清楚原因
  • 本周已在 reportlab 中修复此问题,请尝试从他们的 repo 中查看:bitbucket.org/rptlab/reportlab/commits/…
  • 非常感谢 Greg,问题已解决 - 非常感谢您的帮助!

标签: python google-app-engine python-2.7 reportlab


【解决方案1】:

您的日志显示“ImportError: No module named pwd”

你有密码模块吗?

您可以尝试在交互式 python shell 中导入它来检查

【讨论】:

  • 那不行,appengine运行时没有交互式shell。
  • 感谢 Tim 的帮助 - Greg 链接到的修复解决了问题,但感谢您花时间评论/解释。
猜你喜欢
  • 1970-01-01
  • 2014-09-12
  • 1970-01-01
  • 2010-12-22
  • 1970-01-01
  • 2018-07-24
  • 2021-09-25
  • 1970-01-01
  • 2018-11-30
相关资源
最近更新 更多