python 上传文件

def sendFile(file_path):
file_name = os.path.basename(file_path)
with open(file_path , “rb”)as f1:
base64_str = base64.b64encode(f1.read())#base64 编码
baseStr = base64_str.decode(‘utf-8’) # str
#转换为 json 字符串
fileData = json.dumps({// 参数呀
“baseStr”:baseStr,
“fileType”:“2”,
“filekind”:“1”,
“id”:“123123123123132”
})

    jsonDataArr = [] #文件信息数组
    jsonDataArr.append(fileData)
    jsonData = json.dumps({"file_data":jsonDataArr})
    headers = {
        "Content-Type": "application/json; charset=UTF-8"
    }
    #print(json.dumps(jsonDataArr))

    response = requests.post(url, data=jsonData, headers=headers)
    return response.text