问题
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?
回答1:
I solved this by enabling 'access for less secure apps' in the Google account settings: https://www.google.com/settings/u/1/security/lesssecureapps
来源:https://stackoverflow.com/questions/27510527/how-to-authenticate-google-appegine-python-remote-api-access