Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 Windows本地appengine用法:oauth2client ImportError_Python 2.7_Google App Engine_Oauth2client - Fatal编程技术网

Python 2.7 Windows本地appengine用法:oauth2client ImportError

Python 2.7 Windows本地appengine用法:oauth2client ImportError,python-2.7,google-app-engine,oauth2client,Python 2.7,Google App Engine,Oauth2client,我正在使用App Engine Standard,开发一个Python后端服务,在某个时候,我告诉自己: “嘿,为什么不在使用远程数据存储时在本地尝试运行服务器?” 我可以在本地运行这段代码,但我不明白为什么远程api存根会抛出错误: “文件”C:\ProgramFiles(x86)\Google\Cloud SDK\google cloud SDK\platform\google\u appengine\google\appengine\ext\remote\u api\remote\u ap

我正在使用App Engine Standard,开发一个Python后端服务,在某个时候,我告诉自己:

“嘿,为什么不在使用远程数据存储时在本地尝试运行服务器?”

我可以在本地运行这段代码,但我不明白为什么远程api存根会抛出错误:

“文件”C:\ProgramFiles(x86)\Google\Cloud SDK\google cloud SDK\platform\google\u appengine\google\appengine\ext\remote\u api\remote\u api\u stub.py“, 第1003行,在ConfigureRemoteApiForOAuth'oauth2client模块:%s'中 (e)

ImportError:使用OAuth凭据需要oauth2client 模块:没有名为oauth2client的模块”

尽管如此,根据pip的说法,我已经安装了oauth2client(当我运行
pip安装时,我看到了这一点——升级oauth2client

提前感谢您的帮助

编辑:

我的问题不是重复的。我确实在lib文件夹中安装了google api客户端,并确保“appengine_config.py”文件与必要的行一起放置到位

它仍然没有解决我的问题,所以我将提供更多的细节

这是my main.py(负责GAE的默认服务)或至少是它的一个脱脂版本:

import os
import datetime
import dev_appserver

from google.appengine.ext.remote_api import remote_api_stub
from google.appengine.api import apiproxy_stub_map

dev_appserver.fix_sys_path()
local_urlfetch_stub = apiproxy_stub_map.apiproxy.GetStub('urlfetch')

def configure_remote_api_dev_safe (host):
  if not os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/'):
    logging.info("running on local server")
    remote_api_stub.ConfigureRemoteApiForOAuth(host, '/_ah/remote_api')
    apiproxy_stub_map.apiproxy.ReplaceStub('urlfetch', local_urlfetch_stub)
  else:
    logging.info("running on remote server")

def configure_remote_api_dev_unsafe (host):
  if not os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/'):
    remote_api_stub.ConfigureRemoteApiForOAuth(host, '/_ah/remote_api')
  else:
    logging.info("running on remote server")


class Main(webapp2.RequestHandler):

  def post(self):
    configure_remote_api_dev_safe ('{}.appspot.com'.format(app))
    test = Test(createdAt=datetime.datetime.utcnow())
    test.put()
    self.response.write("done")


app = ndb.toplevel(webapp2.WSGIApplication({('/', Main)}, debug=True))
当我请求默认服务时,会出现以下错误:

PATH_TO_PROJECT_FOLDER>dev_appserver.py PATH_TO_PROJECT_FOLDER
INFO     2018-07-20 10:45:17,740 devappserver2.py:178] Skipping SDK update check.
INFO     2018-07-20 10:45:18,117 api_server.py:274] Starting API server at: http://localhost:53725
INFO     2018-07-20 10:45:18,151 dispatcher.py:270] Starting module "default" running at: http://localhost:8080
INFO     2018-07-20 10:45:18,153 admin_server.py:152] Starting admin server at: http://localhost:8000
INFO     2018-07-20 10:46:57,006 instance.py:294] Instance PID: 5940

WARNING  2018-07-20 08:46:57,565 sandbox.py:1086] The module _winreg is whitelisted for local dev only. If your application relies on _winreg, it is likely that it will not function properly in production.
INFO     2018-07-20 08:46:57,757 main.py:35] running on local server
ERROR    2018-07-20 08:46:57,760 webapp2.py:1528] Use of OAuth credentials requires the oauth2client module: No module named oauth2client
Traceback (most recent call last):
File "SDK_PATH\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1511, in __call__
rv = self.handle_exception(request, response, e)
File "SDK_PATH\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "SDK_PATH\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "SDK_PATH\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1077, in __call__
return handler.dispatch()
File "SDK_PATH\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 547, in dispatch
return self.handle_exception(e, self.app.debug)
File "SDK_PATH\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 545, in dispatch
return method(*args, **kwargs)
File "PATH_TO_PROJECT_FOLDER\main.py", line 125, in post
configure_remote_api_dev_safe ('{}.appspot.com'.format(app))
File "PATH_TO_PROJECT_FOLDER\main.py", line 38, in configure_remote_api_dev_safe'/_ah/remote_api')
File "SDK_PATH\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\remote_api\remote_api_stub.py", line 1003, in ConfigureRemoteApiForOAuth 'oauth2client module: %s' % e)
ImportError: Use of OAuth credentials requires the oauth2client module: No module named oauth2client
ERROR    2018-07-20 08:46:57,765 wsgi.py:279]
Traceback (most recent call last):
File "SDK_PATH\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 267, in Handle
result = handler(dict(self._environ), self._StartResponse)
File "SDK_PATH\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\ndb\tasklets.py", line 1108, in add_context_wrapper
return synctaskletfunc(*args, **kwds)
File "SDK_PATH\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\ndb\tasklets.py", line 1087, in synctasklet_wrapper
return taskletfunc(*args, **kwds).get_result()
File "SDK_PATH\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\ndb\tasklets.py", line 1057, in tasklet_wrapper
result = func(*args, **kwds)
File "SDK_PATH\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1519, in __call__
response = self._internal_error(e)
File "SDK_PATH\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1511, in __call__
rv = self.handle_exception(request, response, e)
File "SDK_PATH\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "SDK_PATH\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "SDK_PATH\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1077, in __call__
return handler.dispatch()
File "SDK_PATH\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 547, in dispatch
return self.handle_exception(e, self.app.debug)
File "SDK_PATH\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 545, in dispatch
return method(*args, **kwargs)
File "PATH_TO_PROJECT_FOLDER\main.py", line 125, in post
configure_remote_api_dev_safe ('{}.appspot.com'.format(app))
File "PATH_TO_PROJECT_FOLDER\main.py", line 38, in configure_remote_api_dev_safe '/_ah/remote_api')
File "SDK_PATH\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\remote_api\remote_api_stub.py", line 1003, in ConfigureRemoteApiForOAuth 'oauth2client module: %s' % e)
ImportError: Use of OAuth credentials requires the oauth2client module: No module named oauth2client
INFO     2018-07-20 10:46:57,782 module.py:880] default: "POST / HTTP/1.1" 500 -
我希望这是更多的解释。再次感谢您的帮助提前

解决方案:(感谢@Dan Cornilescu)

=>永远不要忘记“导入dev_appserver”和对“dev_appserver.fix_sys_path()的调用”

由于代码版本控制(一个糟糕的选择),我一开始就把它们弄丢了,而我认为我一切都做对了


然而,我还没有完成,我正面临一个新问题,我将在一个新问题中键入它,因为它与这个问题的原因无关(我希望在某个时候不会丢失任何其他内容)。[如果你对新问题感到好奇,它会]

将相关评论转换为答案

您显示的代码段似乎缺少示例中明显需要的设置部分:


如果有关系,请不要这样做,但该示例还显示了一个
dev\u appserver.fix\u sys\u path()
你没有。那是因为我在复制粘贴到我的问题时错过了它,谢谢你指出了这一点。我相应地编辑了。没有:/I抱歉@DanCornilescu和snakecharmerb我完全错过了你的答案。我根据解决方案更新了我的问题(一段非常愚蠢的代码丢失)
try:
    import dev_appserver
    dev_appserver.fix_sys_path()
except ImportError:
    print('Please make sure the App Engine SDK is in your PYTHONPATH.')
    raise