Giter Site home page Giter Site logo

Comments (34)

larsblumberg avatar larsblumberg commented on July 19, 2024 10

I had the same error and then I found this log entry in my application logs:

googleapi: Error 403: Access Not Configured. Cloud SQL Administration API has not been used in project [...] before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/sqladmin.googleapis.com/overview?project=[...] then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry., accessNotConfigured

After enabling the Google Cloud SQL API and redeploying the application the SQL connection did work. I don't know if that was a coincidence.

from getting-started-python.

ssenchenko avatar ssenchenko commented on July 19, 2024 1

@larsblumberg I did try enabling Amin API but it didn’t help. Finally, I managed to get it running on GAE. After I created the Cloud SQL instance in the same region as my App Engine, socket file appeared in place. You guys may check if a region can cause this issue.

from getting-started-python.

edgartanaka avatar edgartanaka commented on July 19, 2024 1

I was facing this issue and what got me out of it was adding to app.yaml:

`

beta_settings:
cloud_sql_instances: <cloud_sql_instance_name>:us-central1:<db_name>,<cloud_sql_instance_name>:us-central1:<db_name>,<cloud_sql_instance_name>:us-central1:<db_name>

`

You can do it for several databases.

from getting-started-python.

theacodes avatar theacodes commented on July 19, 2024

@andrewsg can you take a look at this?

from getting-started-python.

andrewsg avatar andrewsg commented on July 19, 2024

I've repoened the internal issue tracking this intermittent failure. @mikeklinker129 as the problem appears to come and go, can you please try again and let me know if the problem persists today?

from getting-started-python.

andrewsg avatar andrewsg commented on July 19, 2024

If it does persist, in order to rule out a configuration issue, could you please post or email me your app.yaml and config.py files with the project ID, password and other sensitive information redacted? As an example, see the redacted config.py in this comment: #92 (comment)

from getting-started-python.

mikeklinker129 avatar mikeklinker129 commented on July 19, 2024

Thanks @andrewsg -- I think the problem comes and goes... I was able to deploy to another project, however last time I tried to start from scratch and a new project, it kept giving me this error. I will try to set up a new project, and get back to you whether or not I am still seeing the error.

from getting-started-python.

andrewsg avatar andrewsg commented on July 19, 2024

That indeed sounds like the other reports of intermittent issues. Thanks for your report, I'll keep track of the bug internally as well.

from getting-started-python.

thoaitrieu avatar thoaitrieu commented on July 19, 2024

MySQL its not running on localhost, use

mysql -h ip_address -u user

from getting-started-python.

JungjaeKimB avatar JungjaeKimB commented on July 19, 2024

@larsblumberg Google changed API's name. Now it is named "Google Cloud SQL API". Thank you for information.
After I enabled "Google Cloud SQL API", this error is disappeared.

from getting-started-python.

ssenchenko avatar ssenchenko commented on July 19, 2024

I have the same issue in the tutorial. (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on 'localhost' ([Errno 2] No such file or directory)" Connection fails when deployed to AppEngine. The issue though persists. I have tried more than 5 times for 3 days

from getting-started-python.

larsblumberg avatar larsblumberg commented on July 19, 2024

@JungjaeKimB thanks, I've updated my comment

@ssenchenko did you follow my suggestion above?

from getting-started-python.

tra0x avatar tra0x commented on July 19, 2024

@andrewsg I believe you can resolve this issue based on @larsblumberg's suggestion above.

On the Overview page, update 'Before you begin'.1.b to mention enabling Google Cloud SQL API, currently only Google Cloud SQL is enabled by default when the project is created. This solved for problem for me, after following all other instructions exactly in the tutorial.

from getting-started-python.

 avatar commented on July 19, 2024

I am having the same issue, although I have already enabled the SQL admin API.

from getting-started-python.

igorsavinkin avatar igorsavinkin commented on July 19, 2024

@larsblumberg I did try enabling Amin API but it didn’t help. Finally, I managed to get it running on GAE. After I created the Cloud SQL instance in the same region as my App Engine, socket file appeared in place. You guys may check if a region can cause this issue.

Let me check.

from getting-started-python.

thomasburling avatar thomasburling commented on July 19, 2024

@larsblumberg Thank you very much for your post! I was having this SQL connection issue and after extensive troubleshooting I found the issue was caused because the Cloud SQL instance was deployed to region = "west1" and the Cloud App Engine was deployed to region = "west2"

To resolve the issue I just created a new sql database instance and database in the "west2" and updated the "config.py" & "app.yaml" with the updated database information!

Thanks again!

@larsblumberg I did try enabling Amin API but it didn’t help. Finally, I managed to get it running on GAE. After I created the Cloud SQL instance in the same region as my App Engine, socket file appeared in place. You guys may check if a region can cause this issue.

from getting-started-python.

digitebs avatar digitebs commented on July 19, 2024

@thomasburling still doenst work getting Can't connect to MySQL server on 'localhost' ([Errno 2] No such file or directory)

from getting-started-python.

kurtisvg avatar kurtisvg commented on July 19, 2024

Hey folks,

If you are having trouble connecting to Cloud SQL from AppEngine, take a look at the "Connecting from AppEngine" documentation.

Specifically, if you are having issues with 'Can't connect to MySQL server on 'localhost' for GAE-Standard', make sure you are connecting via the unix socket provided at /cloudsql/<INSTANCE_CONNECTION_NAME> (AppEngine Standard doesn't provide a TCP connection option)

from getting-started-python.

mikeklinker129 avatar mikeklinker129 commented on July 19, 2024

FYI to anyone searching, I was seeing this error from not updating my app.yaml, under beta_settings: cloud_sql_instances.

from getting-started-python.

altaisukh avatar altaisukh commented on July 19, 2024

I encountered these errors today. I double checked the following and still continue to encounter the problem:

  1. Updated cloud_sql_instances under beta_settings
  2. Updated APIs to grant permissions

Specifically, following the instructions for python-docs-samples/app-engine/flexible/cloudsql

from getting-started-python.

42force avatar 42force commented on July 19, 2024

HI,
Were you able to resolve your issue @altaisukh ?
I am encountering this today, and I am out of my wit - trying to reproduce every steps/instructions.

Thanks!

from getting-started-python.

altaisukh avatar altaisukh commented on July 19, 2024

from getting-started-python.

QuintinSheridan avatar QuintinSheridan commented on July 19, 2024

from getting-started-python.

glorevenhite avatar glorevenhite commented on July 19, 2024

Is it solved? I still experience this error though I did try above solutions. Enable APIs, delete localhost, creating a new database with the same region, etc. I

from getting-started-python.

kurtisvg avatar kurtisvg commented on July 19, 2024

Hey folks,

Just to reiterate, this is a common issue caused when users miss a step in the instructions. I encourage you to take a look at the "Connect from App Engine page" and make sure to note the differences between Standard/Flexible runtimes:

  1. Standard runtimes provide a unix socket at /cloudsql/<INSTANCE_CONNECTION_NAME>. This uses the App Engine standard service account to authenticate to the project the Cloud SQL instance is in, so make sure it has the correct permissions.

  2. Flexible run-times require an update to the app.yaml, and support both TCP and Unix Sockets. There is an example here.

from getting-started-python.

42force avatar 42force commented on July 19, 2024

from getting-started-python.

markguindi1 avatar markguindi1 commented on July 19, 2024

Hmm, I encountered the same error when I first deployed. My app.yaml and config.py files were in order. However, I did notice the following things:

  • I hadn't enabled the Cloud SQL Admin API (something that was mentioned above, and from looking at the logs it seemed that API needed to be enabled, even though it's not listed in the tutorial)
  • When I deployed, my local Python Virtual Environment was not activated (I'm not sure if this would make a difference though)

So I first activated the Cloud SQL Admin API, and tried accessing the application again from the cloud url. It returned the same error.

Then, I activated my Python Virtual Environment with all the dependencies, and redeployed using the gcloud app deploy command, while my virtual environment was activated. When I tried accessing the app from the cloud this time, it worked.

So it seems hard to tell what made it work. Maybe I just had to enable the Cloud SQL Admin API (but then again, when I enabled it without redeploying, it didn't work). Maybe I was supposed to have my Python Virtual Environment activated during deployment (I'm still a beginner at using GCP, so I'm not sure how it handles dependencies and libraries, so I'm not really sure if this would make a difference). Or maybe it just wasn't working for some unknown reason, and redeploying just did the trick.

from getting-started-python.

wvwhome avatar wvwhome commented on July 19, 2024

For my testing: 1) Cloud SQL Admin API must be enabled 2) The App Engine and SQL Instance must be in the same Region.

from getting-started-python.

er1k1 avatar er1k1 commented on July 19, 2024

Enable Cloud SQL Admin API (not just Cloud SQL) and redeploy - not necessary to deploy from virtuel env.
Sql proxy doesn't have to be running - as you would expect that is just for local connection

from getting-started-python.

tc64 avatar tc64 commented on July 19, 2024

Hey folks,

Just to reiterate, this is a common issue caused when users miss a step in the instructions. I encourage you to take a look at the "Connect from App Engine page" and make sure to note the differences between Standard/Flexible runtimes:

  1. Standard runtimes provide a unix socket at /cloudsql/<INSTANCE_CONNECTION_NAME>. This uses the App Engine standard service account to authenticate to the project the Cloud SQL instance is in, so make sure it has the correct permissions.
  2. Flexible run-times require an update to the app.yaml, and support both TCP and Unix Sockets. There is an example here.

@kurtisvg

Thanks for pointing this out. Would you mind clarifying something further?

In a standard python environment I use the following to connect to the db:

conn = pymysql.connect(user=os.environ['DB_USER'],
                           password=os.environ['DB_PASS'],
                           unix_socket='/cloudsql/{}'.format(os.environ['DB_CONN']),
                           db=os.environ['DB_NAME'],
                           cursorclass=pymysql.cursors.DictCursor,
                           autocommit=True)

after setting environment variables using configs.

In the flex environment, I understand that I need to add something like:

beta_settings:
  cloud_sql_instances: <INSTANCE_CONNECTION_NAME>

What's confusing me is, what exactly is the relationship between <INSTANCE_CONNECTION_NAME> and how I'm constructing the socket path above? Would I substitute whatever I have stored in DB_CONN (cf above python code) for <INSTANCE_CONNECTION_NAME> (cf above app.yaml beta_settings ...)?

from getting-started-python.

kurtisvg avatar kurtisvg commented on July 19, 2024

@tc64 - This example here shows how to pass the INSTANCE_CONNECTION_NAME in as an environment variable and use it in the unix_socket path.

from getting-started-python.

denver768 avatar denver768 commented on July 19, 2024

I'm having this same issue. It WAS working a couple days ago, and then stopped and I've been pulling my hair out trying to figure it out... only to realize: OperationalError(2003, "Can't connect to MySQL server on 'localhost' ([Errno 2] No such file or directory)"))" UGH. Definitely not closed.

from getting-started-python.

kiptoomm avatar kiptoomm commented on July 19, 2024

I experienced this issue when running a flask app locally against a remote CloudSQL db instance (using cloud_sql_proxy). My SQLALCHEMY_DATABASE_URI Connection looked like:

mysql+pymysql://{<user-name}:{<user-password>}@{<db-hostname>}/{<database-name>}?unix_socket=/cloudsql/{<connection-name>}

Turns out connections to CloudSQL can only use either TCP or unix socket, not both. Apparently the proxy uses TCP connection

Solution: remove "unix_socket" param when running locally against the live URI so it looks like this:

mysql+pymysql://{<user-name}:{<user-password>}@{<db-hostname>}/{<database-name>}

from getting-started-python.

kurtisvg avatar kurtisvg commented on July 19, 2024

@kiptoomm To clarify, you can use either a TCP socket or a Unix socket using the proxy. Your mistake was trying to pass both arguments to the mysql driver at the same, which caused the driver to fail.

from getting-started-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.