response 得到如下的 json:
{'additionalErrors': None,
'data': {'contentType': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'file': 'UEsDBBQACAAIAAAAAAAAAAAAAAAAAAAAAAATAAAAeGwvdGhlbWUvdGhlbWUxLnhtbOyZz2/bNhT...
(there are still about 11k characters)
...hsL3N0eWxlcy54bWxQSwUGAAAAAAsACwDGAgAASB4AAAAA',
'name': 'export-data.xlsx'},
'error': False,
'errorText': ''}
有了这些数据,是否可以将文件下载到计算机上?
我不知道如何解决这个问题
当您收到此响应时,您已经下载了该文件,它只是以 Base64 格式编码。要解码它,你可以这样做:
import base64
resp = ... # get your JSON response
decoded = base64.b64decode(resp["data"]["file"])
with open("/some/path", "wb") as f:
f.write(decoded)