首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将bytestream添加到请求正文中

将bytestream添加到请求正文中
EN

Stack Overflow用户
提问于 2014-09-13 01:50:59
回答 1查看 235关注 0票数 0

我有代码:

代码语言:javascript
复制
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请求之前,不要将字节流转换为字符串--字节流应该直接写入请求。”

代码语言:javascript
复制
    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类不能隐式转换为字符串。那么如何将字节流直接写入请求呢?

EN

回答 1

Stack Overflow用户

发布于 2014-09-13 02:17:40

原来,Docusign的解决方案是以字节为单位发送所有内容。对于使用带转换的字符串写入字节,没有特定于Python的解决方案。

请参阅Create Docusign envelope with REST API using document bytes: "cannot convert"

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25814002

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档