python - 从字典而不是文件路径设置 ["GOOGLE_APPLICATION_CREDENTIALS"]
问题描述
我正在尝试从 dict 设置环境变量,但在连接时出现错误。
#service account pulls in airflow variable that contains the json dict with service_account credentials
service_account = Variable.get('google_cloud_credentials')
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]=str(service_account)
错误
PermissionDeniedError: Error executing an HTTP request: HTTP response code 403 with body '<?xml version='1.0' encoding='UTF-8'?><Error><Code>AccessDenied</Code><Message>Access denied.</Message><Details>Anonymous caller does not have storage.objects.get access to the Google Cloud Storage object.</Details></Error>'
阅读时,如果我使用并指向文件,则没有问题。
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]=/file/path/service_account.json
我想知道有没有办法将 dict 对象转换为类似对象的 os 路径?我不想将 json 文件存储在容器上,而且气流/谷歌文档根本不清楚。
解决方案
Python stringio 包允许您创建由字符串支持的类似文件的对象,但这在这里没有帮助,因为此环境变量的使用者需要文件路径,而不是类似文件的对象。我认为不可能做你想做的事情。您是否有理由不想将凭据放入文件中?
推荐阅读
- ios - 在启动屏幕故事板中按比例重新缩放 UIImageView
- c# - 如何将 IEnumarable 从视图发送回控制器
- java - QuickFIX/J - 使用市场数据的最佳方式
- python - 如何使用 twisted 的 SerialPort/Protocol 类定义 i2c 地址
- javascript - 如何将孩子附加到具有随机数作为 id 的 div 中?
- android - setTag() 和 getTag() 到底是做什么用的?
- python - MySQL python连接器:“在字节格式化期间并非所有参数都转换”
- c++ - 从 iPhone 相机拍摄的视频似乎被 OpenCV 旋转了 90 度?我该如何解决这个问题?
- angular - 实现了动态嵌套的角度材质菜单,但一次菜单列表不会打开
- python-3.x - 如何使用 Selenium webdriver 定位元素 - 市场 h4 为空白