【问题标题】:How to authenticate Google Appegine (Python) Remote API access如何验证 Google Appegine (Python) 远程 API 访问
【发布时间】:2015-02-15 02:41:36
【问题描述】:

我编写了一个脚本,它应该在计算机上本地运行并修改一些 GAE 数据存储条目。这就是我连接到 GAE 的方式:

def auth_func():
   return ('username@gmail.com','topsecret')
   #return ('seconduser@gmail.com','topsecret2')

def connect():
   remote_api_stub.ConfigureRemoteApi(None,'/_ah/remote_api', auth_func, 'myapp.appspot.com', secure=True)
   remote_api_stub.MaybeInvokeAuthentication()

当我尝试对远程 API 进行身份验证时,只要我使用实际创建 appengine 的帐户,一切都会正常工作。 在 GAE 权限中,我添加了第二个用户作为“所有者”,他接受了邀请,但由于某种原因,ConfigureREmoteApi 总是给出“无效的用户名或密码”。作为错误。 我对第二个用户的密码进行了三次检查——绝对正确。 这是我得到的堆栈跟踪:

Invalid username or password.
Invalid username or password.
Invalid username or password.
Traceback (most recent call last):
  File "./create_updater_entry.py", line 182, in <module>
    remote_api_stub.MaybeInvokeAuthentication()
  File "c:/Program Files (x86)/Google/google_appengine\google\appengine\ext\remote_api\remote_api_stub.py", line 740, in MaybeInvokeAuthentication
    datastore_stub._server.Send(datastore_stub._path, payload=None)
  File "c:/Program Files (x86)/Google/google_appengine\google\appengine\tools\appengine_rpc.py", line 405, in Send
    f = self.opener.open(req)
  File "c:\WinPython-32bit-2.7.6.4\python-2.7.6\lib\urllib2.py", line 410, in open
    response = meth(req, response)
  File "c:\WinPython-32bit-2.7.6.4\python-2.7.6\lib\urllib2.py", line 523, in http_response
    'http', request, response, code, msg, hdrs)
  File "c:\WinPython-32bit-2.7.6.4\python-2.7.6\lib\urllib2.py", line 448, in error
    return self._call_chain(*args)
  File "c:\WinPython-32bit-2.7.6.4\python-2.7.6\lib\urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "c:\WinPython-32bit-2.7.6.4\python-2.7.6\lib\urllib2.py", line 531, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 401: Unauthorized

远程 api 访问是否仅限于创建 GAE 的用户? 或者是否涉及一些身份验证令牌的缓存(例如在 urllib2 中)?

【问题讨论】:

  • 尝试在未登录的情况下在浏览器中访问/_ah/remote_api/,然后在出现提示时以第二个用户身份登录。如果身份验证成功,您应该会看到“此请求未包含必要的标头”。在浏览器中。如果这不起作用,那么您的帐户仍然存在基本身份验证问题。
  • 您也可以尝试运行remote_api_shell.py(在google_appengine SDK 目录中)并使用辅助帐户登录。如果可行,则将问题缩小到脚本。

标签: python google-app-engine remoteapi


【解决方案1】:

我通过在 Google 帐户设置中启用“访问不太安全的应用程序”解决了这个问题:https://www.google.com/settings/u/1/security/lesssecureapps

【讨论】:

  • 为我工作,但我必须将 URL 中的 /u/1 更改为 /u/0 才能更改我的主要帐户的设置。
猜你喜欢
  • 1970-01-01
  • 2011-05-15
  • 2017-01-30
  • 1970-01-01
  • 2023-01-31
  • 1970-01-01
  • 2019-12-18
  • 2017-11-28
  • 1970-01-01
相关资源
最近更新 更多