Can't download data via appcfg.py. "Application Default Credentials are not available" error - google-app-engine

This has worked for years. Today is not working.
Running appcfg.py download_data --flags..., and cannot get properly authorized.
Ran gcloud auth login
and got back:
Saved Application Default Credentials.
You are now logged in as [correct#gmail.com].
Your current project is [correct].
but when I run appcfg.py download_data ... I get this error:
raise ApplicationDefaultCredentialsError(ADC_HELP_MSG)
oauth2client.client.ApplicationDefaultCredentialsError: The
Application Default Credentials are not available. They are available if
running in Google Compute Engine. Otherwise, the environment variable
GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file
defining the credentials. See
https://developers.google.com/accounts/docs/application-default
credentials for more information.
I updated the Google Cloud SDK, and now get a different error:
client.py:539 Attempting refresh to obtain initial access_token
client.py:797 Refreshing access_token
Error 302: --- begin server output ---
--- end server output ---
I have also set the credentials in Terminal:
set GOOGLE_APPLICATION_CREDENTIALS "https://www.myurl/credentials.json"
set CLOUDSDK_PYTHON_SITEPACKAGES 1
gcloud config set project "correct_project_name"
I have also tried setting the env_variable flag in the appcfg command:
--env_variable=GOOGLE_APPLICATION_CREDENTIALS:"https://www.myurl/credentials.json"
Seems to be a GAE bug. Removing the login:admin from the remote_api handler in app.yaml fixes it in production, but not local dev server. The 302 was telling me that the app was trying to redirect, perhaps to a Google login page. Was never seeing the prompt asking for email and password.
handlers:
- url: /remote_api
script: google.appengine.ext.remote_api.handler.application
#login: admin <-- removing admin fixes it in production
secure: always
On the dev server, removing the admin login yields this:
client.py:797 Refreshing access_token
Error 401: --- begin server output ---
You must be logged in as an administrator to access this.
--- end server output ---
Did Google change something in the --oauth2 workflow? I appear to be authorized, but the download crashes at the auth step.
Thanks.

Seems to be a bug in GoogleAppEngineLauncher-1.9.27, where it does not allow a login prompt. When reverting back to 1.9.26, it works. Interestingly, my gcloud components still have the 1.9.27 version:
>$ gcloud version
Google Cloud SDK 0.9.83
alpha 2015.10.08
app 2015.10.16
app-engine-python 1.9.27
beta 2015.10.08
core 2015.10.16
core-nix 2015.09.03
gcloud 2015.10.16
temporary solution: go to https://console.developers.google.com/storage/browser/appengine-sdks/featured/ to get version 1.9.26
Submitted bug report: https://code.google.com/p/google-cloud-sdk/issues/detail?id=340

Related

Google App Engine - Can't download localhost datastore for uploading to production server?

I have a set of data that I would like to use for production but I can't seem to get appcfg.py to download the localhost datastore. I have localhost:8080/_ah/remote_api on in app.yaml then, in the SDK shell, i ran
appcfg.py download_data --filename=local.db --url=http://localhost:8080/_ah/remote_api -A [MYAPPID]
I get this error message:
You must be logged in as an administrator to access this.
I can't find a way to authenticate my google account as the admin. any advice?
This is a general issue of remote_api admin authentication to the local development server, you may want to star it: https://code.google.com/p/googleappengine/issues/detail?id=12445. Several workaround suggestions in there (YMMV according to other posts)
The most recent one (2 days old) looks promising:
Workaround for appcfg.py upload_data to local dev server,
"Refreshing due to a 401" issue. Tested using Java dev server 1.9.42:
Log into the local dev server Development Console in a browser.
Open your browser's dev tools and pull the value for the dev_appserver_login cookie.
Edit lib/oauth2client/oauth2client/client.py in the app.
Find "def new_request" function. Before line self.apply(headers) in this function, add:
headers['Cookie'] = 'dev_appserver_login=your-cookie-value-here';
Run the upload_data command.
There's also this recipe, successful at the time, but it might be a bit old now:
appcfg.py shows You must be logged in as an administrator

Remote implementation for app_identity_service.GetAccessToken failed at GAE PHP dev

Google App Engine SDK for PHP (at local environment) returns error on any try to use Google Cloud Storage. Error message is:
Fatal error: Uncaught exception 'google\appengine\runtime\RPCFailedError' with message 'Remote implementation for app_identity_service.GetAccessToken failed' in /media/data/home/vladimir/setup/gae/google_appengine/php/sdk/google/appengine/runtime/RemoteApiProxy.php on line 92
It exactly repeats the problem described here:
App engine update breaks CloudStorage in dev php env
Test code from the question above shows the same result.
I tried App Engine SDK for PHP versions 1.9.19, 1.9.20, 1.9.21 without success.
On Win10 this issue can be solved by generating an application-default credentials file:
D:\Workspace\Sourcecode>gcloud auth application-default login
Credentials saved to file: [C:\Users\Otje\AppData\Roaming\gcloud\application_default_credentials.json]
And then setting the environment in commandline:
D:\Workspace\Sourcecode>SET GOOGLE_APPLICATION_DEFAULT=C:\Users\Otje\AppData\Roaming\gcloud\application_default_credentials.json
Seems to me GAE on local just outputs limited error information when it can't find the right credentials to succesfully connect to remote endpoint.
It seems that it was GAE's server side issue. They fixed it. I discovered that it started to work as expected today without any changes applied by me.

google appengine deployment authorization problems

Im having problems deploying my GAE. I've got two running already so I should have all the right lirbaries and whatnot. But obviously Im missing something.
I registered my applet with googe appengine developers.
i enter the app_id in the app.yaml of the project as application name.
in cmd, i go to google_appengine and run the "appcfg.py update" on the root directory of my project. "C:/Development/GAE/projectname"
type in email and pw,
and then i get this error msg
12:47 AM Application: processing#######; version: 1
12:47 AM Host: appengine.google.com
12:47 AM
Starting update of app: processing######, version: 1
12:47 AM Getting current resource limits.
Password for ############gmail.com: Invalid username or password.
2014-09-19 00:47:36,404 ERROR appcfg.py:2416 An error occurred processing file '': HTTP Error 401: Unauthorized. Aborting.
Error 401: --- begin server output ---
Must authenticate first.
--- end server output ---
Any ideas what Im missing? Ive triple-checked all these steps cause thats all i can think of.
My App.yaml contains this
application: processing######
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /statics
static_dir: statics
- url: /sketches
static_dir: sketches
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
- name: jinja2
version: latest
Ive upgraded my GAE to the latest version too, still no change. I also tried uploading it to a different application, same problem.
Ive added 2 static folder I use for to run Processing embedded in my website.
PS my app runs fine locally and there's nothing that throws errors or doesnt compile. I think the fault lies somewehre else.
Cheers
Ok so as usual, more research eventually revealed the answer. And stackoverflow.
Guess I missed this first because it specified with php.Stack Overflow Question
Basically i wasnt doing anything wrong afterall, the permission problem was that it was being blocked by my google account.
I had to go to my Account Security permissions, and enable access from less-secure devices.
This must be a new, recent setting Google changed, becuase Ive already deployed 2 apps before.
To mention here for other people with the same problem:
First go through the steps I went through to make sure everything is set up correctly.
Then you should solving it the way I did.
Otherwise you can try setting it up so you can upload without password, this might avoid the problem if it lies somewehre else --oauth without pw
Finally I read that for some people the problem was in timezones. When the time on their computer was different to GAE or server I think that lead to miscommunication, so double-check that your time is set correctly and that it agrees with the time you see in the Launcher Log.
well for me the below 02 options worked
appcfg.py update . --oauth2 --noauth_local_webserver
The authentication flow was :
the command and options generated a url in stdout, which i copied and accessed from my browser, the browser generated a code, which I gave in my command line. I could see appcfg as one of the apps under connected apps and services of my google account.
It seems like an error with your user or password.
Are you sure you can access the project in the developer console, the email configured under permissions is the one which you are using to connect and the app id in yaml file is the same ID on the developers console? If so, the only thing I can imagine is a fail in your password.
Maybe a key pressed? Try typing it in a text processor.
A last idea, deploy the app via the launcher of the sdk. Add the existing app in the file menu (search the app.yaml file) and click deploy to see if there you can authenticate.

Google app engine launcher: Invalid username or password

I've download google app engine (python) for windows and install it. Then I went to console.developers.google.com/project and create new project. After that, I launched google app engine launcher, create new application and named it as project I have recently create. I click on deploy and constantly getting this error:
03:35 PM Application: udacity-hello-pozdrav; version: 1
03:35 PM Host: appengine.google.com
03:35 PM
Starting update of app: udacity-hello-pozdrav, version: 1
03:35 PM Getting current resource limits.
Password for t******.****#gmail.com: Invalid username or password.
2014-09-06 15:35:56,690 ERROR appcfg.py:2411 An error occurred processing file '': HTTP Error 401: Unauthorized. Aborting.
Error 401: --- begin server output ---
Must authenticate first.
--- end server output ---
2014-09-06 15:35:56 (Process exited with code 1)
You can close this window now.
I've read about appcfg.py but when I enter it in cmd, It says that it's not recognized.
Would be much better if you will use appcfg.py with --oauth2 flag.
Like appcfg.py --oauth2 update /path/to/your/app.
For the first time you will see the browser window where you'll need to allow access to your account. Then you can deploy without entering any credentials and without confirmations. This will work even with 2-step authentication turned on.
The "Invalid username or password" error is due to Google security protection. To overcome this error message and be able to deploy from the Launcher, go to your Google Account Settings, then enable "Access for Less Secure Apps" under Security Check Up.

Downloading data from Google App Engine Application

http://code.google.com/appengine/docs/python/tools/uploadingdata.html
Here it is explained how to download data from a gAE app,
First thing to do is setting up remote_api.
The bulk loader tool communicates with your application running on App Engine using remote_api, a request handler included with the App Engine runtime environment that allows remote applications with the proper credentials to access the datastore remotely. There are two ways to install remote_api: automatically using the builtins directive, or you manually using the url directive.
I enabled it using builtins directive:
i changed app.yaml accordingly
builtins:
- remote_api: on
Its given that this directive finds "include.yaml" file for the remote_api and maps the request handler to /_ah/remote_api. Only administrators of the application can access this URL.
but i never came across include.yaml
after that i tried downloading data using the the commands given there
appcfg.py download_data --application=<app-id> --url=http://<appname>.appspot.com/[remote_api_path] --filename=<data-filename>
i'm getting an error saying permission denied, i'm confused. i am also not able to use "create_bulkloader_config" command, getting the same error, I'm confused, Thanks
Are you using open ID / federated login for your app? The remote API does not work with open ID, but there is a workaround here:
http://blog.notdot.net/2010/06/Using-remote-api-with-OpenID-authentication
Replace
builtins:
- remote_api: on
With
- url: /remote_api
script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
login: admin
You Should run the commandline as an admin user. The permission denied error you are getting refers to the appcfg script not being able to access a local file.

Resources