Search code examples
pythonexceptionpython-requestspylinttry-except

merging exceptions in try/except


I'm an experience Perl programmer relatively new to Python.

I'm writing a simple program which uses requests.get(), in a try/except block. pylint complains my bare 'except:' was too bare, so I made it 'except Exception:', but it makes the same complaint. Is there an alternative to catching all nine exceptions that can be generated in requests, considering I just display a message and quit?

I'm going to list all nine, but I wish there were a simpler way.


Solution

  • import requests
    
    try:
        response = requests.get(request_link',headers=headers)
    except requests.exceptions.RequestException as e:
        print(f"Error: {e}")
    

    This should be able to cover all exception of requests.