[英]I can't figure out how to handle different errors
I have some code that is generating the following response:我有一些生成以下响应的代码:
The request failed: Google returned a response with code 429.请求失败:Google 返回了代码为 429 的响应。
I can't get any of these if statements to trigger even though I'm printing the err variable so I know exactly what it says.即使我正在打印 err 变量,我也无法触发这些 if 语句中的任何一个,所以我确切地知道它说的是什么。 What am I doing wrong here?我在这里做错了什么?
try:
<---irrelevant code--->
except (ResponseError, RuntimeError, TypeError, NameError, KeyError) as err:
print("Key error: {}. {}, while querying {} pausing".format(KeyError, err, stock))
if err == 429:
print("429 error")
<---more actions--->
if err == "The request failed: Google returned a response with code 429."
print("429 error")
<---more actions--->
This question is lacking some context and there are some conceptual mistakes here.这个问题缺乏一些背景,这里有一些概念上的错误。
try:
raise EOFError
except EOFError as e:
print(dir(e))
This will output:这将是 output:
<class 'EOFError'> <类'EOFError'>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.