question

LucaZanna-0336 avatar image
0 Votes"
LucaZanna-0336 asked HebaGamalMohamed-4478 commented

Could not translate host name to address: Temporary failure in name resolution

Dear Support,

I have a PostgreSQL database on Azure and I connect it to via Python.

It worked well until yesterday, and starting today I have the following error message:
OperationalError: (psycopg2.OperationalError) could not translate host name "server_name.postgres.database.azure.com" to address: Temporary failure in name resolution

I have not changed anything in the configuration of the database or my Python script.

Here is what the script looks like:
import pandas as pd
from sqlalchemy import create_engine

engine = create_engine('postgresql+psycopg2://user:password@server_name:5432/database_name?sslmode=require')
df = pd.read_csv('my_file.csv')
df.to_sql('table_name',engine, if_exists = 'replace', index=False)

Do you know what could be the issue?

thank you!

azure-database-postgresql
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @LucaZanna-0336, welcome to Microsoft Q&A forum.

Could you please check below threads on stack as they discuss same issue, it is related to URI encoding the special characters:

Python on Azure Function error

Writing a connection string when password contains special characters

Please let me know if this helps or we can discuss further on the same.

1 Vote 1 ·

Also- I can connect to the PostgreSQL via pgAdmin, so it seems that connecting to it is not the problem

0 Votes 0 ·

Hello @LucaZanna-0336

I started seeing this error recently as well. Are you using VS Code on WSL2 by any chance? As you mentioned, restarting my python application fixes this. I never had this issue before and started seeing this crop up again and again in the past couple of weeks.

-Srini

0 Votes 0 ·

1 Answer

LucaZanna-0336 avatar image
0 Votes"
LucaZanna-0336 answered HebaGamalMohamed-4478 commented

Thank you @AnuragSharma-MSFT, we can close this post.

A simple restart of Python was able to fix this.

Regards

Luca

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Glad to hear it worked out for you.

0 Votes 0 ·

Hi @LucaZanna-0336, could you please clarify how what python restart means in case it is in the production?

0 Votes 0 ·