【发布时间】:2020-10-21 06:50:33
【问题描述】:
我将以ConvertApi 为例。如果我将它集成到我的 python 代码中,例如:
try:
#Calling API here
except Exception as e:
print(e)
并获取响应码
{
"Code": 4013,
"Message": "User credentials not set, secret or token must be passed."
}
有没有一种方法可以打印我自己的文本。据我所知,我可以做到这一点
try:
#Calling API here
except:
print('It didn\'t work')
但是如果我得到400 Bad Request,我想说“检查你的连接”,500 Internal Server Error 的“文件转换失败”等等。任何指导将不胜感激。
【问题讨论】:
-
你怎么称呼它?如果您可以获得更具体的异常,则它可能会将响应代码作为属性。
-
@PeterWood 响应代码类似于
{ "Code": 4013, "Message": "User credentials not set, secret or token must be passed." } -
编辑问题。让它很棒。了解如何How to Ask 以及如何创建minimal reproducible example。
-
@PeterWood 我刚刚编辑了它