Python 3.x 将ByTestStream添加到请求正文中
我有密码:Python 3.x 将ByTestStream添加到请求正文中,python-3.x,docusignapi,Python 3.x,Docusignapi,我有密码: with open('thesis.pdf', 'rb') as f: filename = f.read() 我正在尝试将字节添加到Docusign请求中,如下所述: “在将字节流添加到DocuSign请求之前,不要将其转换为字符串——字节流应直接写入请求。” 如以下地址所述: 但是,bytes类不能隐式转换为字符串。那么如何将字节流直接写入请求?对于Docusign,解决方案是以字节发送所有内容。没有特定于Python的解决方案可以通过转换使用字符串写入字节 看
with open('thesis.pdf', 'rb') as f:
filename = f.read()
我正在尝试将字节添加到Docusign请求中,如下所述:
“在将字节流添加到DocuSign请求之前,不要将其转换为字符串——字节流应直接写入请求。”
如以下地址所述:
但是,bytes类不能隐式转换为字符串。那么如何将字节流直接写入请求?对于Docusign,解决方案是以字节发送所有内容。没有特定于Python的解决方案可以通过转换使用字符串写入字节 看
def makeBody(file_stream, envelopeDef):
body = "\r\n\r\n--BOUNDARY\r\n" + \
"Content-Type: application/json\r\n" + \
"Content-Disposition: form-data\r\n" + \
"\r\n" + \
envelopeDef + "\r\n\r\n--BOUNDARY\r\n" + \
"Content-Type: application/pdf\r\n" + \
"Content-Disposition: file; filename=\"thesis.pdf\"; documentId=1\r\n" + \
"\r\n" + \
file_stream + "\r\n" + \
"--BOUNDARY--\r\n\r\n"
return body