merging exceptions in try/except

43 views Asked by At

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.

1

There are 1 answers

1
Arunbh Yashaswi On BEST ANSWER
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.