I have implemented embedded signing using python(Have followed the code given in Docusign
samples). Everything works good with .txt
files.
Just any other format gives me an encoding error.
UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position 351: ordinal not in range(128)
Code:
filepath = os.path.join(settings.MEDIA_ROOT, documentName)
fileContents = open(filepath, "r").read()
requestBody = "\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: text/plain\r\n" + \
"Content-Disposition: file; filename=\"test_doc.txt\"; documentId=1\r\n" + \
"\r\n" + \
fileContents + "\r\n" + \
"--BOUNDARY--\r\n\r\n"
# append "/envelopes" to the baseUrl and use in the request
url = baseUrl + "/envelopes";
headers = {'X-DocuSign-Authentication': AUTHENTICATION_STR, 'Content-Type': 'multipart/form-data; boundary=BOUNDARY',
'Accept': 'application/json'};
http = httplib2.Http()
response, content = http.request(url, 'POST', headers=headers, body=requestBody)
I tried encoding in UTF-8
import codecs
fileContents = codecs.open(filepath,mode='r', encoding='utf-8').read()
Still it doesnt help.
I also tried changing the Content-Type
to : application/pdf
Can anyone suggest a way of doing it?