I have a django==1.4 project (python==2.7) that I wanted to run and make some changes. I am unable to connect to cloud datastore from my local codebase. Right now, when I run the project using dev_appserver.py like:
dev_appserver.py PROJECT_NAME --enable_console
It runs three different servers:
localhost:RANDOM_PORTlocalhost:8080localhost:8000Now I visit http://localhost:8000/console and browse interative console and then run some python script like importing User model and fetching if there is anything there or not. And there isn't, why? Because it connects to the local AppIdentityServiceStub. And obviously there isn't any data unless I create some.
Now I want to connect this codebase to my cloud datastore and I have tried different implementations that are already on stackoverflow and other platforms. One of them is setting environment variable GOOGLE_APPLICATION_CREDENTIALS to a keyfile.json that service account provides. I have the keyfile.json and I have set it to env variable but still I get connected to local datastore which has no data. Let me know if I am running this project wrong? or is there any other way to connect to cloud datastore from my local?
Also, one more thing, when I do not set the env variable GOOGLE_APPLICATION_CREDENTIALS it shows this WARNING:
WARNING 2024-04-22 08:12:02,588 app_identity_stub.py:206] An exception has been encountered when attempting to use Application Default Credentials: File /Users/USER/keyfile.json (pointed by GOOGLE_APPLICATION_CREDENTIALS environment variable) does not exist!. Falling back on dummy AppIdentityServiceStub.
And when I set it to keyfile.json, this warning goes away but still this isn't connecting to the cloud datastore. What could be the reason? What am I doing wrong? Is there any other way to run this code? Any help is appreciated. Thanks
What you need is remote_api. The documentation says
You can use the Remote API to access your application's data store from an app running on your local machine, or from a local interactive Remote API shell.
According to that documentation, you'll have to deploy your application after enabling remote_api. Unfortunately, by default, you can't do that for Python27 since it's reached end of support. To be able to deploy runtimes which have reached end of support, see this documentation
Update
If you use builtins, you can only access remote_api at the path /_ah/remote_api i.e. for remote_api to work, you need to use paths like -
<projectid>.appspot.com/_ah/remote_api/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With