我有代码:
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 everywhere
“在将字节流添加到DocuSign请求之前,不要将字节流转换为字符串--字节流应该直接写入请求。”
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类不能隐式转换为字符串。那么如何将字节流直接写入请求呢?
发布于 2014-09-13 02:17:40
原来,Docusign的解决方案是以字节为单位发送所有内容。对于使用带转换的字符串写入字节,没有特定于Python的解决方案。
请参阅Create Docusign envelope with REST API using document bytes: "cannot convert"
https://stackoverflow.com/questions/25814002
复制相似问题