import requests url = 'wrong url' try: r = requests.get(url) except Exception as e: print(f'There was an error: {e}')