在我的函数中,如果 text_content
是例如德国人,功能失败。通过当前的解决方案,我得到了:
print(type(e))
>>> <class 'google.api_core.exceptions.InvalidArgument'>
我想更具体,所以改为 except Exception as e:
except InvalidArgument as e:
但是,这不起作用。你知道这里出了什么问题吗?
text_content= "Trauben sind gut. Bananen sind schlecht."
try:
sample_analyze_entity_sentiment(text_content)
except Exception as e:
print(type(e))
最佳答案
您需要导入 InvalidArgument
异常。
from google.api_core.exceptions import InvalidArgument
text_content= "Trauben sind gut. Bananen sind schlecht."
try:
sample_analyze_entity_sentiment(text_content)
except InvalidArgument as e:
print(type(e))
关于python - 捕获特定异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58363804/