【发布时间】:2018-11-30 20:06:25
【问题描述】:
我正在尝试为 GCP 服务帐户实施密钥轮换。我设法创建了一个新密钥,然后解码了 base64 编码的privateKeyData,它具有实际的 SA JSON 文件。现在,当我读回文件以进行身份验证时,它给了我这个错误:
'unicode 对象没有 iterKeys()'
我认为是json.dumps 的问题。
data = base64.b64decode(key['privateKeyData']).decode('utf-8')
print data # this prints expected output
with open('file.json', mode='w') as out:
str = json.dumps(data)
print out # this adds \n,\\ to the output
out.write(str)
错误:
AttributeError: 'unicode' object has no attribute 'iterkeys'
json.dumps 之后文件如何转换的虚拟片段:
"{\n \"type\": \"service_account\",\n \"project_id\": \"testproj\",\n \"private_key_id\": \6866996939\"}"\n
【问题讨论】:
标签: python json google-cloud-platform service-accounts