【发布时间】:2019-01-28 09:24:36
【问题描述】:
我想将 Json 的压缩 gzip 上传到 Google 存储中。
我有这个代码:
import datalab.storage as storage
import gzip
path = prefix + '/orders_newline.json.gz'
storage.Bucket('orders').item(path).write_to(gzip.compress(bytes(create_jsonlines(source)),encoding='utf8'), 'application/json')
create_jsonlines(source) 是一个返回 Json Newline Delimited 的函数。
运行此代码给出:
TypeError: string argument without an encoding
Python docs 表示格式为:bytes([source[, encoding[, errors]]]) 我不确定我是否理解它,因为没有示例说明如何使用它。
我也试过了
bytes([(create_jsonlines(source))[,encoding='utf8']])
这给出了:
SyntaxError: invalid syntax
我正在运行 Python 3.5
【问题讨论】:
-
这个直接代码示例的问题是编码 arg 在错误的函数中。
标签: python google-cloud-platform google-cloud-storage google-cloud-datalab