我正在使用Google的google-cloud-storage
Python包访问GCS。当我得到一个403错误,它可能是由于许多不同的原因。默认情况下,Google的SDK仅提供以下消息:
('Request failed with status code', 403, 'Expected one of', <HTTPStatus.OK: 200>)")
使用调试器,我可以更深入地查看库,发现_upload.py
有一个_process_response
方法,可以在其中找到真正的HTTP响应,结果中包含以下消息:
"message": "$ACCOUNT does not have storage.objects.delete access to $BLOB."
Q:有没有办法访问这个更有用的错误代码或原始响应?
我希望向用户展示过期凭据和尝试执行凭据不允许的操作之间的区别
您使用的是
google-cloud-storage
的哪个版本?使用最新版本和此示例:它打印以下内容:
这里的字符串表示形式与
e.message
大致相同:如果您想要更多的结构,可以使用
e._response.json()
:相关问题 更多 >
编程相关推荐