0

I have a flask app in a Paperspace Deployment Docker container. It is connected to a Google Cloud SQL (MySQL).

Here are the variables in the YALM parameters:

env:
  - name: CLOUD_SQL_CONNECTION_NAME
    value: xx.xx.xx.xx
  - name: CLOUD_SQL_USERNAME
    value: my_user
  - name: CLOUD_SQL_PASSWORD
    value: xxxxx
  - name: CLOUD_SQL_DATABASE_NAME
    value: db_01

And the related code:

HOST =os.environ.get('CLOUD_SQL_CONNECTION_NAME') 
USER = os.environ.get('CLOUD_SQL_USERNAME')
PWD = os.environ.get('CLOUD_SQL_PASSWORD')
SQLDB = os.environ.get('CLOUD_SQL_DATABASE_NAME')
CHARSET = os.environ.get('CLOUD_SQL_CHARSET')

SQLALCHEMY_DATABASE_URI = ('mysql+pymysql://{user}:{password}@{connection_name}/{database}').format(user=USER, password=PWD,database=SQLDB, connection_name=HOST)

app.config['SQLALCHEMY_DATABASE_URI'] =  SQLALCHEMY_DATABASE_URI

The container is working well if I run it on the local PC, but not in a Paperspace cloud.

The GCloud SQL server never answers, even if I have the Paperspace service's IP address in the authorized IPs from GCould SQL.

The IP has been obtained thanks to a ping to the service endpoint URL.

Here is the error I get from the Paperspace Deployment server.

sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on '[CLOUD_SQL_CONNECTION_NAME(IP)]' (timed out)")
(Background on this error at: https://sqlalche.me/e/14/e3q8)

Why the GCloud SQL server never answers? Is there any port or authorization that needs to be activated?

  • The error **(timed out)** often means a firewall issue. Using a ping to determine a services address will often result in the wrong address. I do not know your service (Paperspace) but you will need to either lookup the correct egress IP address or use the Cloud SQL Auth Proxy (program or Python library). – John Hanley Nov 01 '22 at 04:16
  • Thanks a lot, I'll check this. – NicolasSens Nov 01 '22 at 08:02
  • @JohnHanley After further investigation, I've found out that Paperspace has the port 3306 closed, which block any request to the MySQL Database on GCloud. I've asked them to unlock port 3306. Not sure yet if they can. Do you know any trick to avoid this issue? – NicolasSens Nov 02 '22 at 20:04
  • I have not used their service. However, I cannot image the reason why they would block you from connecting to a MySQL server. Which ports do they allow? – John Hanley Nov 02 '22 at 20:10
  • I've tested several ports (5000, 8000, 3306, ...), and only the port 80 is working. – NicolasSens Nov 02 '22 at 20:44
  • This does not make any sense. Get an official answer from Paperspace and post that in your question. – John Hanley Nov 02 '22 at 20:48
  • Actually, I was authorizing a wrong IP address in GCloud. The command "curl api.ipify.org" gives the correct one and I was able to connect to the database. – NicolasSens Nov 07 '22 at 21:23

0 Answers0