Python Forum
Thread Rating:
  • 3 Vote(s) - 2.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error handling not working
Hi, i made a program that reads a URL from textfile and checks if that websites status is <=400, if it is, it will return "website is running" and saves that to a list and checks the next address in the textfile. This works as long as the website is reachable and returns status <= 400.
But when i add a random address, which doesnt exist the program stops running completely. Need help solving this, code below and error also, thank you.

def getApacheStatus(urlStatus):
   r = requests.head(urlStatus['url'])
       if r.status_code <= 400:
           return 'connected'
           return 'website down'
requests.exceptions.ConnectionError: HTTPConnectionPool(host='', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7f8424b7de10>: Failed to establish a new connection: [Errno -2] Name or service not known',))
EDIT by user:
never mind, im stupid. found my mistake as soon as i posted problem, can delete this :D
r = requests.head(urlStatus['url'])
is out of the try/except block, thus making it pointless.
Yes, noticed that soon as i hit "post" :) been watching too much code, stupid mistakes

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error Handling JarredAwesome 5 250 Oct-17-2020, 12:41 AM
Last Post: JarredAwesome
  Error handling using cmd module leifeng 3 442 Jun-06-2020, 06:25 PM
Last Post: leifeng
  Excpetion Handling Getting Error Number gw1500se 4 404 May-29-2020, 03:07 PM
Last Post: gw1500se
  Warning / Error handling in python Prarthana_12 1 2,035 Feb-08-2019, 09:21 PM
Last Post: snippsat
  Help With Error Handling jo15765 6 1,411 Sep-14-2018, 06:27 PM
Last Post: jo15765
  Error Handling/No results from SQL Query JP_ROMANO 7 3,083 Jul-18-2018, 02:31 PM
Last Post: JP_ROMANO
  Error handling parthi1705 0 942 Jun-13-2018, 11:57 AM
Last Post: parthi1705
  Error Handling is weird PythonAndArduino 1 1,367 Nov-09-2017, 05:08 AM
Last Post: Mekire

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020