TypeError:不带编码的字符串参数
发布于 2021-01-29 14:58:59
我想将Json的压缩gzip上传到Google Storage。
我有以下代码:
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换行符分隔的功能。
运行此代码将给出:
TypeError: string argument without an encoding
在Python文档说,格式是:bytes([source[, encoding[, errors]]])
我不知道我把它理解为不存在如何使用它的例子。
我也尝试过
bytes([(create_jsonlines(source))[,encoding='utf8']])
这给出了:
SyntaxError: invalid syntax
我正在运行Python 3.5
关注者
0
被浏览
98
1 个回答