我正嘗試在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