Forums

TimeoutError: [Errno 110] Connection timed out when connecitng to a cloud sql instance via SSL

Hell folks,

I'm trying to establish a connection to my db instance on cloud sql (postgres) and I'm doing so via an SSL cert.

Everything is set up and works fine on my local machine and also on a remote ubuntu distro.

The problem is, with everything set up, when I try to connect to the remote db via SQLAlchemy using an SSL certificate, the following exception gets thrown

Traceback (most recent call last):
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/pg8000/core.py", line 209, in init
(host, port), timeout, source_address
File "/usr/lib/python3.7/socket.py", line 727, in create_connection
raise err
File "/usr/lib/python3.7/socket.py", line 716, in create_connection
sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 3243, in wrap_pool_connect
return fn()
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 310, in connect
return _ConnectionFairy._checkout(self)
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 868, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 476, in checkout
rec = pool._do_get()
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 146, in _do_get
self._dec_overflow()
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 72, in exit
with_traceback=exc_tb,
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 207, in raise

raise exception
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 143, in do_get
return self._create_connection()
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 256, in _create_connection
return _ConnectionRecord(self)
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 371, in init
self.__connect()
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 666, in __connect
pool.logger.debug("Error on connect(): %s", e)
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 72, in exit
with_traceback=exc_tb,
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 207, in raise

raise exception
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 661, in connect
self.dbapi_connection = connection = pool._invoke_creator(self)
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/sqlalchemy/engine/create.py", line 590, in connect
return dialect.connect(cargs, cparams)
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 584, in connect
return self.dbapi.connect(
cargs, cparams)
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/pg8000/init.py", line 129, in connect
replication=replication,
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/pg8000/legacy.py", line 442, in init
super().init(*args,
kwargs)
File "/home/PougnatorGmd/.virtualenvs/orders-to-google-sheet/lib/python3.7/site-packages/pg8000/core.py", line 215, in __init

) from e pg8000.exceptions.InterfaceError: Can't create a connection to host 35.241.182.96 and port 5432 (timeout is None and source_address is None).

What could I be doing wrong here ?

If you upgraded recently, have you tried that code in a console that was created after you upgraded? Otherwise, that just looks like a failure to connect and you will need to check the configuration that you have on your database to make sure that it will allow connections from PythonAnywhere.

I didn't upgrade anything just yet.

But the way I have configured my database is to accept SSL connections only. And that's I'm trying to do, i've installed the certificates the same way I have done it on my machine, but it doesn't work :s

You did upgrade your PythonAnywhere account from a free account to a paid one.

That just looks like the connection is not making it to the machine. With a paid PythonAnywhere account, we do not do anything to connections that you make outside of PythonAnywhere, so the connection is probably being blocked by your cloud database host for some reason. Make sure that the network configuration for your cloud database allows connections from PythonAnywhere.