在Python Google App Engine上使用SignedJwtAssertionCredentials

时间:2015-07-24 14:43:27

标签: python google-app-engine

使用下面的代码段来编辑我的Google云端硬盘帐户上的电子表格的单元格。当我从我的python IDE(不在谷歌应用程序引擎)上运行代码时,这是有效的。

import webapp2
import gspread
from oauth2client.client import SignedJwtAssertionCredentials
import json
from httplib2 import Http
from gspread.exceptions import CellNotFound
import os

# folder = os.path.dirname(os.path.realpath(__file__))
# file_path = os.path.join(folder, 'clientkey.json')
json_key = json.load(open('clientkey.json'))
scope = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
googleClient = gspread.authorize(credentials)

将相同的代码复制到我要部署的Google应用引擎项目时,会显示以下错误。

    Traceback (most recent call last):

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 240, in Handle

    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 299, in _LoadHandler

    handler, path, err = LoadObject(self._handler)

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 85, in LoadObject

    obj = __import__(path[0])

  File "C:\Users\CrowdStar\workspace\AppEngineThinkStudio\DominicProject\main.py", line 3, in <module>

    from oauth2client.client import SignedJwtAssertionCredentials

  File "C:\Users\CrowdStar\workspace\AppEngineThinkStudio\DominicProject\oauth2client\client.py", line 34, in <module>

    import six

ImportError: No module named six

我添加了所需的模块,它会抛出一个错误,说明需要另一个模块。保持添加所需的模块,并继续抛出错误添加其他模块。添加了8个模块只是为了使它工作,它仍然说一些模块即使在外部工作良好的情况下也找不到。我该如何解决这个问题。

1 个答案:

答案 0 :(得分:0)

我看到这是旧的问题,但没有答案,仍然得到意见。如果您只将客户端库安装到系统站点包,则会发生这种情况:

pip install --upgrade google-api-python-client

要将库及其所有必需的依赖项一次性提供到您应用的目录中,以便将它们与您的应用程序一起上传,请使用&#39; -t&#39;标志:

pip install google-api-python-client -t /myappdir