• notice
  • Congratulations on the launch of the Sought Tech site

Python program requests reports Temporary failure in name resolution

       The business has been running normally before, but in the past few days, an error has been reported during operation.

    load json failed: HTTPSConnectionPool(host='...', port=443): Max retries exceeded with url: (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f6e3bf41790>: Failed to establish a new connection: [ Errno -3] Temporary failure in name resolution 

        I found the wrong place, which is the "name resolution temporarily failed" reported when using requests.get in python. Of course, we have a solution for domain name resolution failure.

    1. It is to enter /etc/hosts to add the resolution of the corresponding domain name
, but if there is a new domain name access in the business later, you have to add the domain name resolution again. Why can't the domain name be resolved now? It can also be parsed normally before. It can only be recommended that the domain name resolution service environment has changed.
2. DNS service configuration
Modify the configuration file /etc/resolv.conf, and add the following content to the file to add the effective configuration at the beginning of the line. Because Too many DNS servers configured, the following entries may be ignored Try to put it in front.


        It is speculated that the cause of this problem may be that the nameserver is configured in the original container, but the restarted container does not have the correct nameserver. I saw this conclusion in an article:

    When the host resolv.conf file is not empty and there is no resolv.conf file operation in the container startup command, the container uses the content of the host resolv.conf file by default.
When the host resolv.conf file is empty, the container startup command When there is no resolv.conf file operation, the container will add and to the resolv.conf file

        But here I found that it is not the case. My host resolv.conf file has not been empty, but the resolv.conf in the container I started has a lot of configuration (manual operation), which seems to be related to other docker containers. I will not go into this aspect. .

        In addition, when viewing the /etc/resolv.conf configuration file, I found that there is a search item. The function of search is to complete the short domain name to be accessed. When the domain name is resolved, it will first search for /etc/hosts. If it fails, then it will be based on the nameserver Find the domain name. If these two steps fail, the nameserver will perform search completion, put the search configuration content after the query key characters, and then re-query.



Technical otaku

Sought technology together

Related Topic


Leave a Reply