I'm trying to figure out how to get proper english/ascii error message from a failes requests.get
. for some reason (probably being working with a hebrew locale), I get a jibrish unicode error message. I can deocde the message and display it correctly in hebrew, but I really prefer (for various reasons) that the Exception error text would be in english.
checking Requests Exception source code doesn't even lead me in the right direction, Since I seem to be I'm getting a different exception:
(10060, some encoded error text,')
and the class is: <class 'socket.error'>
.
So I guess we are probably looking at a socket.error
from socket lib. At least as far as I can tell from parsing the Exception args (I can't raise the exception directly, only while running the app, where I do a smelly except Exception as e
and parse e.args
and e.message
).
EDIT: this is the results I get from parsing e.args
, e.message
, e.__class__
(10060, '\xfe\xfe\xf0\xe9\xf1\xe9\xe5\xef \xe7\xe9\xe1\xe5\xf8 \xf0\xeb\xf9\xec \xee\xe0\xe7\xf8 \xf9\xe4\xf6\xe3 \xe4\xee\xe7\xe5\xe1\xf8 \xec\xe0 \xe4\xe2\xe9\xe1 \xeb\xf8\xe0\xe5\xe9 \xec\xe0\xe7\xf8 \xfa\xf7\xe5\xf4\xfa \xe6\xee\xef,'), message: , class: <class 'socket.error'>
the string is encoded 'windows-1255' and decodes to (hebrew):
ניסיון חיבור נכשל מאחר שהצד המחובר לא הגיב כראוי לאחר תקופת זמן,
tranlates to: "connection attempt failed since the connected side didn't respond properly after a time period"
the code raising the Exception:
try:
print ("parsing json from:", srvstr)
getjson = requests.get(srvstr, params=params, auth=(user, password), verify=ssl)
print('url:', getjson.url)
except Exception as e:
args = ", ".join(args)
details = 'args: %s, message: %s, class: %s' % (args, e.message, e.__class__)
So:
how do I set the locale so that requests (or the underlying socket lib if my guess is correct) would return an english/Ascii error message?
Thanks for the help!