Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6743791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:00:17+00:00 2026-05-26T12:00:17+00:00

I have a script running that is testing a series of urls for availability.

  • 0

I have a script running that is testing a series of urls for availability.

This is one of the functions.

def checkUrl(url): # Only downloads headers, returns status code.
    p = urlparse(url)
    conn = httplib.HTTPConnection(p.netloc)
    conn.request('HEAD', p.path)
    resp = conn.getresponse()
    return resp.status

Occasionally, the VPS will lose connectivity, the entire script crashes when that occurs.

File "/usr/lib/python2.6/httplib.py", line 914, in request
  self._send_request(method, url, body, headers)
File "/usr/lib/python2.6/httplib.py", line 951, in _send_request
  self.endheaders()
File "/usr/lib/python2.6/httplib.py", line 908, in endheaders
  self._send_output()
File "/usr/lib/python2.6/httplib.py", line 780, in _send_output
  self.send(msg)
File "/usr/lib/python2.6/httplib.py", line 739, in send
  self.connect()
File "/usr/lib/python2.6/httplib.py", line 720, in connect
  self.timeout)
File "/usr/lib/python2.6/socket.py", line 561, in create_connection
  raise error, msg
socket.error: [Errno 101] Network is unreachable

I’m not at all familiar with handling errors like this in python.

What is the appropriate way to keep the script from crashing when network connectivity is temporarily lost?


Edit:

I ended up with this – feedback?

def checkUrl(url): # Only downloads headers, returns status code.
    try:
        p = urlparse(url)
        conn = httplib.HTTPConnection(p.netloc)
        conn.request('HEAD', p.path)
        resp = conn.getresponse()
        return resp.status
    except IOError, e:
        if e.errno == 101:
            print "Network Error"
            time.sleep(1)
            checkUrl(url)
        else:
            raise

I’m not sure I fully understand what raise does though..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:00:18+00:00Added an answer on May 26, 2026 at 12:00 pm

    If you just want to handle this Network is unreachable 101, and let other exceptions throw an error, you can do following for example.

    from errno import ENETUNREACH
    
    try:
        # tricky code goes here
    
    except IOError as e:
        # an IOError exception occurred (socket.error is a subclass)
        if e.errno == ENETUNREACH:
            # now we had the error code 101, network unreachable
            do_some_recovery
        else:
            # other exceptions we reraise again
            raise
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python script that is running a few ls commands. This script
I have a PHP script (running on a Linux server) that ouputs the names
I have a PHP script running on XAMPP in Windows XP that will open
I have a php script that is running in CLI and I want to
I have a Perl/POE/Tk script running on Win32 ActivePerl that calls executables using system
I have a script that I'm running from the home directory to search for
I have a script that is supposed to sit there, happily running in a
I have an IronPython script that looks for current running processes using WMI. The
I have a python script that ends with running a program (iexpress.exe) in a
Problem: I have a python script that I have running as a service. It's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.