Python On Azure Function Error Is "operationalerror: (psycopg2.operationalerror) Could Not Translate Host Name "mypassword@database_ip" To Address"
I have a python function that connects to Azure Postgresql and selects query some rows. In local run without problem. When I published on Azure and run it I received the below erro
Solution 1:
Rather than using plain string formatting you can use engine.URL.create to protect yourself against "special characters" in the username, password, etc.:
import sqlalchemy as sa
# …
url = sa.engine.URL.create(
drivername="postgresql+psycopg2",
username="username",
password="@password",
host="ip",
port=5432,
database="database",
)
print(url) # postgresql+psycopg2://username:%40password@ip:5432/database
engine = sa.create_engine(url)
``
Solution 2:
The literal @
in your password needs to be URI encoded.
Post a Comment for "Python On Azure Function Error Is "operationalerror: (psycopg2.operationalerror) Could Not Translate Host Name "mypassword@database_ip" To Address""