2016-06-30 7 views
0

私は、DocuSignによって与えられた例を使用して、Python経由でREST APIを使用してエンベロープを送信しています。私はかなりコードを貼り付け、ユーザー名、パスワード、受信者情報などを割り当てました(明らかな理由からコードブロックにはありません)。私の問題は、私は具体的には、INVALID_REQUEST_BODYエラーを取得していますということです。DocuSign API Evnelope Pythonの例文エラーを送信する

import httplib2, json, sys 


authenticateStr = "<DocuSignCredentials>" \ 
      "<Username>" + username + "</Username>" \ 
            "<Password>" + password + "</Password>" \ 
                   "<IntegratorKey>" + integratorKey + "</IntegratorKey>" \ 
                            "</DocuSignCredentials>"; 


# 
# STEP 1 - Login 
# 
url = 'https://demo.docusign.net/restapi/v2/login_information'; 
headers = {'X-DocuSign-Authentication': authenticateStr, 'Accept': 'application/json'}; 
http = httplib2.Http(); 
response, content = http.request(url, 'GET', headers=headers); 

status = response.get('status'); 
if (status != '200'): 
    print("Error calling webservice, status is: %s" % status); 
    sys.exit(); 

# get the baseUrl and accountId from the response body 
data = json.loads(content); 
loginInfo = data.get('loginAccounts'); 
D = loginInfo[0]; 
baseUrl = D['baseUrl']; 
accountId = D['accountId']; 

envelopeDef = "{\"emailBlurb\":\"This comes from Python\"," + \ 
       "\"emailSubject\":\"API Call for adding signature request to document and sending\"," + \ 
       "\"documents\":[{" + \ 
       "\"documentId\":\"1\"," + \ 
       "\"name\":\"test_doc.txt\"}]," + \ 
       "\"recipients\":{" + \ 
       "\"signers\":[{" + \ 
       "\"email\":\"" + signer + "\"," + \ 
       "\"name\":\"Name\"," + \ 
       "\"recipientId\":\"1\"," + \ 
       "\"tabs\":{" + \ 
       "\"signHereTabs\":[{" + \ 
       "\"xPosition\":\"100\"," + \ 
       "\"yPosition\":\"100\"," + \ 
       "\"documentId\":\"1\"," + \ 
       "\"pageNumber\":\"1\"" + "}]}}]}," + \ 
       "\"status\":\"sent\"}"; 

# convert the file into a string and add to the request body 
fileContents = open("test_doc.txt", "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\Dr\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': authenticateStr, 'Content-Type': 'multipart/form-data; boundary=BOUNDARY', 
      'Accept': 'application/json'}; 
http = httplib2.Http(); 
response, content = http.request(url, 'POST', headers=headers, body=requestBody); 
status = response.get('status'); 
if (status != '201'): 
    print("Error calling webservice, status is: %s\nError description - %s" % (status, content)); 
    sys.exit(); 
data = json.loads(content); 
envId = data.get('envelopeId'); 
+0

これは助力ですか? http://stackoverflow.com/questions/25356317/senders-notifications同様のエラーが発生したようです。 –

答えて

3

このライン:ここ

The request body is missing or improperly formatted. Additional text encountered after finished reading JSON content: -. Path '', line 3, position 1. 

はコードがある

envelopeDef + "\r\n\r\n--BOUNDARY\Dr\n" + \ 

はそれに余分な 'D' の文字を持っていました。それを取り外すことができました。

+0

投稿していただきありがとうございます。これをコミュニティの利益のための答えとして受け入れることができますか?どうも – Ergin

関連する問題