2016-03-03 149 views
2

目前我正在试图将字节组发送到Web服务,但我得到的错误信息,这为bytearray不可被序列化:使用请求发送ByteArray的Web服务使用HTTP POST

TypeError: bytearray(b'') is not JSON serializable

我使用下面的代码

发送请求

# Set blob 
with open('demo-file.txt') as file: 
    f = file.read() 
    b = bytearray(f) 
    print a.set_data('5cb9bc4d-c0fd-40ab-8b74-4e62b50d8966', b) 

Set_Data方法:

def set_data(self, path, data): 
    """ 
    Save data in 

    Parameter 
    -------- 
    path (str): Path as string 
    data (bytearray): Data as bytearray 
    """ 

    result = requests.post(self.url + '/set', json = { 'path': path, 'data': data}) 

    # Check status and token 
    if result.status_code == 200: 
     return result.text 

我做错了什么,我必须使用其他一些方法来发送字节码?

谢谢大家!

回答

相关问题