Python Forum
Thread Rating:
  • 3 Vote(s) - 2.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error handling not working
#1
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 www.asdasdasda123sd.com, 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'])
   try:
       if r.status_code <= 400:
           return 'connected'
       else:
           return 'website down'
   except:
       pass
Error:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='www.asdasdasda123sd.com', 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
Reply


Messages In This Thread
Error handling not working - by desudesu - Jun-14-2017, 12:44 PM
RE: Error handling not working - by buran - Jun-14-2017, 12:48 PM
RE: Error handling not working - by desudesu - Jun-14-2017, 02:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  File Handling not working properly TheLummen 8 559 Feb-17-2024, 07:47 PM
Last Post: TheLummen
Star python exception handling handling .... with traceback mg24 3 1,215 Nov-09-2022, 07:29 PM
Last Post: Gribouillis
  Byte Error when working with APIs Oshadha 2 980 Jul-05-2022, 05:23 AM
Last Post: deanhystad
  Help needed with a "for loop" + error handling tamiri 2 2,383 May-27-2022, 12:21 PM
Last Post: tamiri
  Handling Python Fatal Error richajain1785 7 5,757 Oct-14-2021, 01:34 PM
Last Post: Tails86
  Error Handling JarredAwesome 5 2,842 Oct-17-2020, 12:41 AM
Last Post: JarredAwesome
  Error handling using cmd module leifeng 3 2,800 Jun-06-2020, 06:25 PM
Last Post: leifeng
  Excpetion Handling Getting Error Number gw1500se 4 2,326 May-29-2020, 03:07 PM
Last Post: gw1500se
  Warning / Error handling in python Prarthana_12 1 5,060 Feb-08-2019, 09:21 PM
Last Post: snippsat
  Help With Error Handling jo15765 6 4,044 Sep-14-2018, 06:27 PM
Last Post: jo15765

Forum Jump:

User Panel Messages

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