In my code I have a get request as:
response = requests.get(url)
For invalid status code ie non 2xx an exception is raised,
exp_obj = RequestException(response)
Now I want to get the status code from this exception object exp_obj
I tried exp_obj.response.status_code but I am getting AttributeError: 'NoneType' object has no attribute 'status_code'
If I print exp_obj it is same as response object ie <Response [500]>
This feels like an XY problem. But looking at what you are trying to do. You need to check the way
requests.exceptions.RequestException()works.For your
exp_objto contain the response, you have to create the RequestException using named arguments (**kwargs).exp_obj = RequestException(response=response)In your case you should be doing this.