thisAKcode / fastapi_streetart_map

0 stars 0 forks source link

I cannot connect to postgre #5

Closed thisAKcode closed 2 years ago

thisAKcode commented 2 years ago

Hey I played with fastapi as per this video: https://www.youtube.com/watch?v=d_ugoWsvGLI I repeated all steps but at the end I got an error about authentication.

We can take it on next call otherwise here is the way to reproduce it:

cd C:\fastapi_project1\app
uvicorn main:app --reload

the error is:

 conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) connection to server at "localhost" (::1), port 5432 failed: FATAL:  password authentication failed for user "postgres"
thisAKcode commented 2 years ago

it is solved. Sorry I didn't make a real PR , but just merged it to master. it was related to engine configuration I just needed to put my overlycomplicated pw into following:

import urllib.parse
urllib.parse.quote_plus("my_pw_included_tricky_to_encode_chars")

https://docs.sqlalchemy.org/en/14/core/engines.html#escaping-special-characters-such-as-signs-in-passwords

bbelderbos commented 2 years ago

OK this all works, but remember to load DB url from the environment, see https://pybit.es/articles/how-to-handle-environment-variables-in-python/