我有代码:
with open('thesis.pdf', 'rb') as f:
filename = f.read()
我正在尝试将字节添加到Docusign的请求中,如下所示:Very basic stuff - how do I send a document to docusign via REST API? I only see <document bytes go here...> everywhere
&#34;在将字节流添加到DocuSign请求之前,不要将字节流转换为字符串 - 字节流应直接写入请求。&#34;
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
指定于:http://iodocs.docusign.com/APIWalkthrough/requestSignatureFromDocument
但是,bytes类不能隐式转换为字符串。那么如何将字节流直接写入请求?
答案 0 :(得分:0)
事实证明Docusign,解决方案是以字节发送所有内容。没有特定的Python特定解决方案用于使用带转换的字符串写入字节。
请参阅Create Docusign envelope with REST API using document bytes: "cannot convert"