On Fri, Oct 6, 2017 at 9:59 AM, Martin Cigorraga
<martincigorr...@gmail.com> wrote:
> Hi,
>
> I'm trying to create a simple function to check the reachability of a
> Postgres database using the http method GET; if the connection can't be
> established, it should respond with a custom http error number.
>
> This is what I got so far: https://pastebin.com/rh3t6nYN
>
> Being fairly new to Python does not help, for sure, but after trying
> everything I can think of for the last hours I'm stagnant.
> Can anybody give me a hint on which direction I should go? I feel this has
> to be a basic stuff but at the moment I just can't wrap my head over it.
>

See this note on http://docs.sqlalchemy.org/en/latest/core/engines.html:

"""
Note that the Engine and its underlying Pool do not establish the
first actual DBAPI connection until the Engine.connect() method is
called, or an operation which is dependent on this method such as
Engine.execute() is invoked.
"""

Your code probably needs to do something like this:

    engine = sqlalchemy.create_engine(url, client_encoding='utf8')
    connection = engine.connect()

"engine.connect()" will raise an exception if it fails to connect.

Hope that helps,

Simon

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to