Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
710 views
in Technique[技术] by (71.8m points)

python - TypeError: string argument without an encoding

I want to upload compressed gzip of Json into Google Storage.

I have this code:

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')

The create_jsonlines(source) is a function that returns Json Newline Delimited.

Running this code gives:

TypeError: string argument without an encoding

The Python docs says the format is: bytes([source[, encoding[, errors]]]) I'm not sure I understand it as there is no example of how to use it.

I tried also

bytes([(create_jsonlines(source))[,encoding='utf8']])

This gives :

SyntaxError: invalid syntax

I'm running Python 3.5

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...