3

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?

Alex
  • 267
  • 1
  • 2
  • 7
  • Try accessing `/_ah/remote_api/` in a browser while not signed in, then sign in as the second user when prompted. If authentication is successful, you should see "This request did not contain a necessary header." in the browser. If that doesn't work, then you still have a basic authentication problem with the account. – Dan Sanderson Dec 16 '14 at 18:45
  • You can also try running `remote_api_shell.py` (in the `google_appengine` SDK directory) and sign in with the secondary account. If that works, that narrows the issue to the script. – Dan Sanderson Dec 16 '14 at 18:47

1 Answers1

4

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

Alex
  • 267
  • 1
  • 2
  • 7
  • Worked for me, but I had to change the /u/1 in the URL into /u/0 in order to change the setting for my primary account. – Abednego May 29 '15 at 17:54