Advertisement
DeaD_EyE

simple is_online with urlopen

Dec 5th, 2021
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.20 KB | None | 0 0
  1. from urllib.request import urlopen, URLError
  2.  
  3.  
  4. def is_online(url):
  5.     try:
  6.         response = urlopen(url, timeout=1)
  7.     except URLError:
  8.         return False
  9.    
  10.     return response.code == 200
  11.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement