如何导入boto3雅典娜客户例外
我正在使用Boto3与Athena合作,如下所示:
def query_athena(query, output_path):
client = boto3.client('athena')
client.start_query_execution(
ResultConfiguration={'OutputLocation': output_path},
QueryString=query
)
如docs, start_query_execution
may raise InternalServerException
, InvalidRequestException
or <代码> toomanyrequestSexception 。我想对待如下:
def query_athena(query, output_path):
client = boto3.client('athena')
try:
client.start_query_execution(
ResultConfiguration={'OutputLocation': output_path},
QueryString=query
)
except <AthenaException> as e:
deal with e
其中&lt; athenaException&gt;
是我提到的三个例外之一,或者更好的是它们的超类。
我的问题是如何导入这些例外?文档显示它们为 athena.client.exceptions.internalserverexception
,但我似乎在任何boto3模块中都找不到这个athena.client。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的困惑,但弄清楚了。文档中列出的异常不是boto3的内部,而是在boto3抛出客户端错误时响应中包含。
我在解决方案上的第一张照片看起来像这样。它假设您已经处理了S3输出位置,BOTO3会话等:
I ran into the same confusion, but figured it out. The exceptions listed in the docs aren't internal to boto3, but rather contained in the response when boto3 throws a client error.
My first shot at a solution looks like this. It assumes you've handled s3 output location, a boto3 session, etc already: