Python on Amazon Linux 2 fails to resolve remote RDS host

0

I installed Amazon Linux 2 as WSL on my Windows machine. I have a simple Python code to connect AWS RDS, which runs fine on Windows, but fails on Amazon Linux 2, with the following error.

Traceback (most recent call last):
  File "src/oracledb/impl/thin/connection.pyx", line 102, in oracledb.thin_impl.ThinConnImpl._connect_with_address
  File "src/oracledb/impl/thin/protocol.pyx", line 150, in oracledb.thin_impl.Protocol._connect_phase_one
  File "src/oracledb/impl/thin/protocol.pyx", line 262, in oracledb.thin_impl.Protocol._connect_tcp
  File "/usr/local/lib/python3.10/socket.py", line 824, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/local/lib/python3.10/socket.py", line 955, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

I followed instructions on this page to install Python on Amazon Linux 2.

Please advise what might be the cause and what should do to resolve it. Thank you in advance.

Gary Y
asked 10 months ago238 views
2 Answers
0
Accepted Answer

This post helped me to resolve the issue.

Gary Y
answered 10 months ago
profile picture
EXPERT
reviewed a month ago
  • It’s exactly what my answer was.

0

I think WSL uses a different DNS server than your operating system. It uses a docker network dns server.

Try and update your /etc/resolv.conf to the same name server as your windows machine and see if this resolves the issue

This should be a permanent fix https://dev.to/abhiweb/set-persist-google-dns-server-in-wsl2-notes-4364

profile picture
EXPERT
answered 10 months ago
  • Thank you Gary Mclean! Since I have AWS VPN connection, I updated the nameserver to the DNS server associated to the VPN, but it didn't work. The one associated with my wi-fi connection didn't work either. Any more suggestions?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions