Saturday, August 4, 2018

Re: [google-cloud-sql-discuss] Re: Couldn't connect to CloudSQL(accessNotConfigured)

Thanks  Jiasheng Yang,
Thanks you for your timely help.

I followed the steps as given below and it helps me to resolve the issue:

1.  Ran "gcloud auth application-default login "
       This gave a warning message given below :
        "You are running on a Google Compute Engine virtual machine.
     The service credentials associated with this virtual machine       will automatically be used by Application Default       Credentials, so it is not necessary to use this command.         If you decide to proceed anyway, your user credentials may be visible       to others with access to this virtual machine. Are you sure you want       to authenticate with your personal account?       Do you want to continue (Y/n)?"
        I Entered 'Y", it gives a URL, to generate a token.
       I generated the token and given in the command prompt.
2.  Ran the Proxy setting :
      a. download proxy using the below url
           wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
      b.  chmod +x cloud_sql_proxy
      c. sudo ./cloud_sql_proxy -dir=/cloudsql -instances=<INSTANCE_CONNECTION_NAME> &
      It shows the confirmation of running of proxy
3. Change the 
      create_engine('postgresql+psycopg2://DB-USERID:PASSWORD@/DATABASE-NAME?host=/cloudsql/<INSTANCE_CONNECTION_NAME>')
After doing all the above 3-steps , it works for me. to runn my python flax application with Postgresql , work in coloud project.
4. Done the below change to make it work after deployment.
    #[START env]  env_variables:      # Replace user, password, database, and instance connection name with the values obtained      # when configuring your Cloud SQL instance.      SQLALCHEMY_DATABASE_URI: postgresql+psycopg2://DATABASE-USER-ID:PASSWORD@/DATABASE-NAME?host=/cloudsql/<INSTANCE_CONNECTION_NAME>  #[END env]    #[START cloudsql_settings]  # Replace project and instance with the values obtained  when configuring your  # Cloud SQL instance.  beta_settings:      cloud_sql_instances: <INSTANCE_CONNECTION_NAME>  #[END cloudsql_settings]
5. Done the below change in my main.py to get the environment variable:
   import os 
     engine = create_engine(os.environ['SQLALCHEMY_DATABASE_URI'])
   Session = sessionmaker(bind=engine)

Just want know , are the steps followed to make it work correct or is there any other steps there to make it work.

Thanks
Binaya


On Fri, Aug 3, 2018 at 6:28 PM James Qualls <qualls.james@gmail.com> wrote:
Cloud SQL Proxy is built on the golang SDK. There is a standard way that all google cloud libraries load application credentials.
In this case it is likely related to your `$PWD/application_default_credentials.json`. You can fix the issue by running `gcloud auth application-default login`.

This will init the correct credentials into that file and you should be able to start the proxy with your user account and default credentials. Not with a service account.    

On Thursday, November 9, 2017 at 6:56:46 PM UTC-7, Fady (Google Cloud Platform) wrote:

Thank you for the information, and the troubleshooting steps. Following this help article, connecting a mysql client using the Cloud SQL Proxy requires enabling the Cloud SQL API and creating a service account with the " Role, Cloud SQL > Cloud SQL Client" privilege (least authority) before starting the proxy. " Alternatively, you can use the primitive Editor role by selecting Project > Editor, but the Editor role includes permissions across Google Cloud Platform."


On Thursday, November 9, 2017 at 6:41:42 PM UTC-5, Jiasheng Yang wrote:
Got it. It turns out to be that I cannot connect to CloudSQL through proxy.
I resolved that by creating a service account with owner access to this project and using -crendential_file when running the proxy.

On Wednesday, November 8, 2017 at 2:48:17 PM UTC-8, Jiasheng Yang wrote:
Hello all,

I was following the tutorial of running Django application on App Engine(https://cloud.google.com/python/django/appengine).
I downloaded the source code and followed this doc step by step but when I tried to "Run the app on your local computer", I got connection error from cloud_sql_proxy.
Error message like "couldn't connect to "django-mysite-185418:us-central1:instance-polls": ensure that the account has access to "django-mysite-185418:us-central1:instance-polls" (and make sure there's no typo in that name). Error during createEphemeral for django-mysite-185418:us-central1:instance-polls: googleapi: Error 403: Access Not Configured. Cloud SQL Administration API has not been used in project 563584335869 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/sqladmin.googleapis.com/overview?project=563584335869 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry., accessNotConfigured".

To be specific, I couldn't connect with the CloudSQL database through mySql client. I got the same error message when executing "mysql --host 127.0.0.1 --user root --password" in console.

I'm pretty sure I have enable the Cloud SQL Admin API for long time in that project, and there's no typo in that name.

Any help would be treasured. Thanks a lot.

Jiasheng

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/6aba7ef9-c3b0-40fc-9800-5de7bbd325a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/CAKaZEErUEhfBH%2BCxt9s%3Dg2vnwywZQmbGt_ax%3DQbd0AuVy1qOJw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment