Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 将ByTestStream添加到请求正文中_Python 3.x_Docusignapi - Fatal编程技术网

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