如何验证Google Appegine(Python)远程API访问 [英] How to authenticate Google Appegine (Python) Remote API access

查看:125
本文介绍了如何验证Google Appegine(Python)远程API访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

DEF连接():
remote_api_stub.ConfigureRemoteApi(无,'/ _ah / remote_api',auth_func,'myapp.appspot.com',secure = True)
remote_api_stub.MaybeInvokeAuthentication()

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

 无效的用户名或密码。 
无效的用户名或密码。
无效的用户名或密码。
Traceback(最近一次调用最后一次):
在< module>文件中的第182行./create_updater_entry.py
remote_api_stub.MaybeInvokeAuthentication()
文件c:/ Program Files(x86)/Google/google_appengine\google\appengine\ext\remote_api\remote_api_stub.py,第740行,在MaybeInvokeAuthentication
datastore_stub._server.Send(datastore_stub._path,payload = None)
文件c:/ Program Files(x86)/ Google / google_appengine\google\appengine\tools\appengine_rpc。 py,第405行,发送
f = self.opener.open(req)
文件c:\ WinPython-32bit-2.7.6.4\python-2.7.6\lib\ urllib2.py,第410行,打开
response = meth(req,response)
文件c:\ WinPython-32bit-2.7.6.4\python-2.7.6\lib\\ \\urllib2.py 线路523,在HTTP_RESPONSE
'的http',请求,响应代码,味精,HDRS)
文件 C:\WinPython-32位-2.7.6.4\python- 2.7.6\lib\urllib2.py,第448行,错误
返回self._call_chain(* args)
文件c:\ WinPython-32bit-2.7.6.4\p ython-2.7.6\lib\urllib2.py 线路382,在_call_chain
结果= FUNC(*参数)
文件 C:\WinPython-32位-2.7.6.4\ python-2.7.6\lib\urllib2.py,第531行,在http_error_default
中引发HTTPError(req.get_full_url(),code,msg,hdrs,fp)
urllib2.HTTPError:HTTP错误401:未授权

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

解决方案

我通过启用'在Google帐户设置中访问安全性较低的应用: https://www.google .com / settings / u / 1 / security / lesssecureapps

I wrote a script that is supposed to run locally on a computer and modify some GAE data store entries. This is how I connect to my 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()

When I try to authenticate to the remote API everything works fine as long as I use the account that actually created the appengine. In the GAE permissions I added a second user as 'owner' who accepted the invitation but for some reason ConfigureREmoteApi always gives 'Invalid username or password.' as error. I triple-checked the password for the second user - it is definitely correct. This is the stack trace I get:

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

Is the remote api access limited to the user who created the GAE? Or is there some caching of authentication tokens (e.g. in urllib2) involved?

解决方案

I solved this by enabling 'access for less secure apps' in the Google account settings: https://www.google.com/settings/u/1/security/lesssecureapps

这篇关于如何验证Google Appegine(Python)远程API访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆