【发布时间】:2014-01-08 09:16:00
【问题描述】:
如何在 GAE 中通过 webapp 使用像 requests 这样的外部库? SOF 上有各种相关的问题,但没有一个专门回答我的问题。
【问题讨论】:
标签: python google-app-engine web-applications webapp2
如何在 GAE 中通过 webapp 使用像 requests 这样的外部库? SOF 上有各种相关的问题,但没有一个专门回答我的问题。
【问题讨论】:
标签: python google-app-engine web-applications webapp2
你可以在你的项目目录中创建目录,让它成为distlibs。在main.py 中,您应该将此目录添加到sys.path:
import sys
sys.path[0:0] = ['distlibs']
你可以从distlibs dir 中获得import 库(例如wtforms):
from wtforms import validators
...
对于 requests 库,一旦你解压 ithub(github.com/kennethreitz/requests) 会发现它有一个名为 requests 的目录。这就是您需要在代码中放置的内容。
【讨论】:
requests 时返回错误。如果我取消注释,该应用程序将正常工作。我只是想通过将任何库放入 distlibs 来确认您的意思。你能详细说明这部分吗?
GAE github.com/greggy/gae-blog 的简单应用程序,也许对你有帮助。