简体   繁体   中英

I'm getting an operational error, as described below, when trying to connect to a remote postgreSQL server through sqlalchemy

Here is the error message:

OperationalError: (psycopg2.OperationalError) could not connect to server: No route to host
    Is the server running on host "5432" (0.0.21.56) and accepting
    TCP/IP connections on port 5432?

Here's what I've tried:

import sqlalchemy 
from sqlalchemy import create_engine
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
engine = create_engine('postgresql+psycopg2://tcccinxdlfzchw:86b3a71b125f827c343a88d71811fa2096744455e75abd5b5e15077bb7a910cb@5432/d2lr09vchdiec3')

Base = automap_base()

Base.prepare(engine, reflect=True)

It's from this base.prepare that I am getting the above error message, and I have tried modifying my postgresql.conf file to listen to all addresses, and my pg-hba.conf file to be host all all md5. Then restarted the server, and I'm still getting the error. Have any idea?

I found the answer, the engine wasn't connecting simply because I wasn't providing the correct URI, which can usually be found in the details of your host site, next to port number, password, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM