Python 捕获特定异常

Python 捕获特定异常,python,Python,在我的函数中,如果text\u content是德语,则函数失败。使用当前的解决方案,我得到了回报: print(type(e)) >>> <class 'google.api_core.exceptions.InvalidArgument'> 您需要导入InvalidArgument异常 从google.api_core.exceptions导入无效参数 text_content=“Trauben sind gut.Bananen sind schlecht。”

在我的函数中,如果
text\u content
是德语,则函数失败。使用当前的解决方案,我得到了回报:

print(type(e))
>>> <class 'google.api_core.exceptions.InvalidArgument'>

您需要导入
InvalidArgument
异常

从google.api_core.exceptions导入无效参数
text_content=“Trauben sind gut.Bananen sind schlecht。”
尝试:
样本分析实体情感(文本内容)
除作为e的无效辩论外:
印刷品(e类)

您需要导入
无效辩论
异常

从google.api_core.exceptions导入无效参数
text_content=“Trauben sind gut.Bananen sind schlecht。”
尝试:
样本分析实体情感(文本内容)
除作为e的无效辩论外:
印刷品(e类)

什么叫“它不工作”?到底发生了什么?什么不起作用?你的一般尝试/排除或实施无效辩论?什么是“它不起作用”?到底发生了什么?什么不起作用?您是否尝试/排除或实施无效辩论?
text_content= "Trauben sind gut. Bananen sind schlecht."
try:
    sample_analyze_entity_sentiment(text_content)
except Exception as e:
    print(type(e))