TypeError: string argument without an encoding

后端 未结 3 2057
执念已碎
执念已碎 2020-12-20 11:10

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

I have this code:

import datalab.storage as storage
import gzip
path = prefix + \'/orde         


        
3条回答
  •  爱一瞬间的悲伤
    2020-12-20 11:56

    You are probably only one step away from the answer.

    See bytesarray() and bytes for the function usage (you may need to change python version of the document).

    And it says:

    The optional source parameter can be used to initialize the array in a few different ways:

    • If it is a string, you must also give the encoding (and optionally, errors) parameters; bytearray() then converts the string to bytes using str.encode().
    • If it is an integer, the array will have that size and will be initialized with null bytes.
    • If it is an object conforming to the buffer interface, a read-only buffer of the object will be used to initialize the bytes array.
    • If it is an iterable, it must be an iterable of integers in the range 0 <= x < 256, which are used as the initial contents of the array.

    Notice that the square bracket indicates that those parameters can be omitted, it is not an array type of python language.

    So you should use bytes(create_jsonlines(source), encoding='utf8').

提交回复
热议问题