In my code, I've made some post requests. How can I catch connection refused error in that call?
try:
headers = {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}
response = requests.request("POST", local_wallet_api + "v1/wallet/get_public_keys", headers=headers)
res = json.loads(response.text)
except Exception as e:
if e.errno == errno.ECONNREFUSED:
print("connection refused")
sys.exit(141)
I've tried the above code, but it is not working as it says e
has no errno
parameter. Is there any proper way to handle this kind of error?