-1

I have a python script which use rest-api to communicate with my server.
I am using python-requests to handle rest-api.
The script has a loop and try-except for handling errors to keep it running.

On centos, I accidentally mis-configured the dns and started my script.

Here is the error:

HTTPConnectionPool(host='host.com', port=80): Max retries exceeded with url: //rest/url (Caused by NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known',))

Then I reconfigured the dns properly without restarting the script, but the script still didn't work unless restart it. Same error.
Programs started after dns reconfiguration like ping, web browsers were working fine.

Same problem happens for ping if it is started before dns reconfiguration, but not for firefox.
It seems that firefox took a while to adapt new dns configuration.

On debian, this problem does't exist.
When I reconfigured the dns properly, the script or other programs started to work almost immediately.

Is there anything special with dns on centos?
Can my script adapt new dns configuration without restarting?

==========================
python-requests version I tested:
2.11.1, 2.12.4, 2.13.0 On centos
2.11.1, 2.12.4 on debian

centos version tested:
6.2, 7.3-1611

debian version tested:
debian-sid latest update

python version:
2.7.13rc1 on debian
2.7.5 on centos 7.3-1611
2.6.6 on centos 6.2

dwSun
  • 11
  • 2

1 Answers1

0

problem solved by calling __res_init in glibc.

More details see Python not getting IP if cable connected after script has started and http://bugs.sugarlabs.org/attachment/ticket/1940/network.py.patch

Community
  • 1
  • 1
dwSun
  • 11
  • 2