Random "[Errno -2] Name or service not known" errors

Ozgur Akcali

I am populating a local database using a third party service. I have a list of urls (around 500). I am calling each url in a loop, and updating my database with the returned data. The code flow looks like this:

for url in urllist:
    req = urllib.urlopen(url)
    data = json.loads(req.read())
    req.close()

    #update the db using data here

Whenever I run this piece of code, the script fails at random points with the error message "Name or service not known". This doesn't have anything with the urls because the script fails at random points (i.e. at 50th iteration in one run, and at 60th iteration in another)

What could be the reason for this?

sheh

if you use a bad proxy or there are network problems you can try this:

for url in urllist:
    retry = 0
    while True: # retry request
        try:
            req = urllib.urlopen(url)
            resp_data = req.read() # in call read() network still processing
        except Exception as e: # TODO need more detailed handling
            if retry > 3: # 3 this is serious problem. exit
                raise e
            retry += 1 # retry
        else:
            data = json.loads()
            req.close() # not needed
            break

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

AWS [Errno -2] Name or service not known

From Dev

AWS [Errno -2] Name or service not known

From Dev

Newbie, error: [Errno -2] Name or service not known

From Dev

rabbtimqadmin - Could not connect: [Errno -2] Name or service not known

From Dev

What does "urlopen error [Errno -2] Name or service not known" mean?

From Dev

socket.gaierror: [Errno -2] Name or service not known

From Java

jupyter throwing error: socket.gaierror: [Errno -2] Name or service not known

From Dev

easy_install not working : Getting error [Errno -2] Name or service not known -- Some packages may not be found

From Dev

jupyter throwing error: socket.gaierror: [Errno -2] Name or service not known

From Dev

easy_install not working : Getting error [Errno -2] Name or service not known -- Some packages may not be found

From Dev

urllib.error.URLError: <urlopen error [Errno -2] Name or service not known>

From Dev

Docker/Boot2Docker/Fig + RabbitMQ host issue; pika.exceptions.AMQPConnectionError: [Errno -2] Name or service not known

From Dev

Eclipse random unknown type/resolving errors

From Dev

VB6 random double overflow errors

From Dev

random orderBy in AngularJS 1.2 returns 'infdig' errors

From Dev

Latest Resharper giving me random build errors

From Dev

Getting random 404 errors in IIS PHP site

From Dev

The intel-microcode package causes random errors

From Dev

The intel-microcode package causes random errors

From Dev

Serial port returning random errors on Wyse client

From Dev

Python Threaded Timer Returning Random Errors

From Dev

JavaScript canvas: "Random" errors with collision detection

From Dev

Random EXT4 FS errors

From Dev

Why is Azure giving me random 500 errors?

From Dev

Getting random errors when setting up Joomla with nginx instead of apache

From Java

mdadm RAID5 random read errors. Dying disk?

From Dev

Random errors while doing Enter-PSSession in powershell

From Dev

Random nan errors when importing matplotlib.pyplot

From Dev

Errors with xutility (<chrono> <random> C++ standard libraries)

Related Related

  1. 1

    AWS [Errno -2] Name or service not known

  2. 2

    AWS [Errno -2] Name or service not known

  3. 3

    Newbie, error: [Errno -2] Name or service not known

  4. 4

    rabbtimqadmin - Could not connect: [Errno -2] Name or service not known

  5. 5

    What does "urlopen error [Errno -2] Name or service not known" mean?

  6. 6

    socket.gaierror: [Errno -2] Name or service not known

  7. 7

    jupyter throwing error: socket.gaierror: [Errno -2] Name or service not known

  8. 8

    easy_install not working : Getting error [Errno -2] Name or service not known -- Some packages may not be found

  9. 9

    jupyter throwing error: socket.gaierror: [Errno -2] Name or service not known

  10. 10

    easy_install not working : Getting error [Errno -2] Name or service not known -- Some packages may not be found

  11. 11

    urllib.error.URLError: <urlopen error [Errno -2] Name or service not known>

  12. 12

    Docker/Boot2Docker/Fig + RabbitMQ host issue; pika.exceptions.AMQPConnectionError: [Errno -2] Name or service not known

  13. 13

    Eclipse random unknown type/resolving errors

  14. 14

    VB6 random double overflow errors

  15. 15

    random orderBy in AngularJS 1.2 returns 'infdig' errors

  16. 16

    Latest Resharper giving me random build errors

  17. 17

    Getting random 404 errors in IIS PHP site

  18. 18

    The intel-microcode package causes random errors

  19. 19

    The intel-microcode package causes random errors

  20. 20

    Serial port returning random errors on Wyse client

  21. 21

    Python Threaded Timer Returning Random Errors

  22. 22

    JavaScript canvas: "Random" errors with collision detection

  23. 23

    Random EXT4 FS errors

  24. 24

    Why is Azure giving me random 500 errors?

  25. 25

    Getting random errors when setting up Joomla with nginx instead of apache

  26. 26

    mdadm RAID5 random read errors. Dying disk?

  27. 27

    Random errors while doing Enter-PSSession in powershell

  28. 28

    Random nan errors when importing matplotlib.pyplot

  29. 29

    Errors with xutility (<chrono> <random> C++ standard libraries)

HotTag

Archive