I am running into an issue when attempting to connect to postgresDB
. I have a Database URL with port # that I use to create a connection. I am using sqlalchemy
python library to connect to postgres db.
My database URL is of the following format from the docs:
from sqlalchemy import create_engine
from sqlalchemy import inspect
# pg8000
engine = create_engine('postgresql+pg8000://postgres:***@hostname:5432/db_name')
postgres_engine = create_engine(connection_string)
Traceback Error / Exception below:
InterfaceError: Can't create a connection to host xxxxxxx and port xxx (timeout is None and source_address is None).
The above exception was the direct cause of the following exception:
InterfaceError Traceback (most recent call last)
<ipython-input-10-18d2b71bc4ec> in <module>
----> 1 postgres_engine.table_names()
~/opt/anaconda3/lib/python3.7/site-packages/sqlalchemy/engine/base.py in table_names(self, schema, connection)
2254 """
2255
-> 2256 with self._optional_conn_ctx_manager(connection) as conn:
2257 return self.dialect.get_table_names(conn, schema)
2258
~/opt/anaconda3/lib/python3.7/contextlib.py in __enter__(self)
110 del self.args, self.kwds, self.func
111 try:
--> 112 return next(self.gen)
113 except StopIteration:
114 raise RuntimeError("generator didn't yield") from None
~/opt/anaconda3/lib/python3.7/site-packages/sqlalchemy/engine/base.py in _optional_conn_ctx_manager(self, connection)
2038 def _optional_conn_ctx_manager(self, connection=None):
2039 if connection is None:
-> 2040 with self._contextual_connect() as conn:
2041 yield conn
2042 else:
~/opt/anaconda3/lib/python3.7/site-packages/sqlalchemy/engine/base.py in _contextual_connect(self, close_with_result, **kwargs)
2240 return self._connection_cls(
2241 self,
-> 2242 self._wrap_pool_connect(self.pool.connect, None),
2243 close_with_result=close_with_result,
2244 **kwargs
~/opt/anaconda3/lib/python3.7/site-packages/sqlalchemy/engine/base.py in _wrap_pool_connect(self, fn, connection)
2278 if connection is None:
2279 Connection._handle_dbapi_exception_noconnection(
-> 2280 e, dialect, self
2281 )
2282 else:
~/opt/anaconda3/lib/python3.7/site-packages/sqlalchemy/engine/base.py in _handle_dbapi_exception_noconnection(cls, e, dialect, engine)
1545 util.raise_from_cause(newraise, exc_info)
1546 elif should_wrap:
-> 1547 util.raise_from_cause(sqlalchemy_exception, exc_info)
1548 else:
1549 util.reraise(*exc_info)
~/opt/anaconda3/lib/python3.7/site-packages/sqlalchemy/util/compat.py in raise_from_cause(exception, exc_info)
396 exc_type, exc_value, exc_tb = exc_info
397 cause = exc_value if exc_value is not exception else None
--> 398 reraise(type(exception), exception, tb=exc_tb, cause=cause)
399
400
InterfaceError: (pg8000.exceptions.InterfaceError) .
(Background on this error at: http://sqlalche.me/e/rvf5)