使用Python代码在Google云端存储上传原始JSON数据
问题描述:
我正尝试在Google云端平台上传原始JSON数据。但我收到此错误:使用Python代码在Google云端存储上传原始JSON数据
TypeError: must be string or buffer, not dict
代码:
def upload_data(destination_path):
credentials = GoogleCredentials.get_application_default()
service = discovery.build('storage', 'v1', credentials=credentials)
content = {'name': 'test'}
media = http.MediaIoBaseUpload(StringIO(content), mimetype='plain/text')
req = service.objects().insert(
bucket=settings.GOOGLE_CLOUD_STORAGE_BUCKET,
body={"cacheControl": "public,max-age=31536000"},
media_body=media,
predefinedAcl='publicRead',
name=destination_path,
)
resp = req.execute()
return resp
代码通过改变StringIO(content)
合作StringIO(json.dumps(content))
有什么建议吗? – Naveen