python - PARTNER_AUTHENTICATION_FAILED:未找到或禁用指定的集成商密钥。未指定 Integrator 密钥
问题描述
我正在开发一个 Django Web App,它用于通过电子邮件向用户发送文档,并为此目的使用 Docusign API。我正在使用 JWT 授权身份验证并已成功获取工作正常的访问令牌。
现在,我想通过电子邮件向用户发送文档以进行签名。为此,我使用以下代码:
from django.shortcuts import render
from django.http import JsonResponse
from docusign_esign import EnvelopeDefinition, Recipients, Tabs, SignHere, Signer, CarbonCopy, Document, EnvelopesApi, ApiClient
import base64
ACCESS_TOKEN = 'MY_ACCESS_TOKEN'
ACCOUNT_ID = 'MY_ACCOUNT_ID'
BASE_PATH = 'demo.docusign.net/restapi'
def create_document(signer_name, signer_email, cc_name, cc_email):
return f"""
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body style="font-family:sans-serif;margin-left:2em;">
<h1 style="font-family: "Trebuchet MS", Helvetica, sans-serif;
color: darkblue;margin-bottom: 0;">World Wide Corp</h1>
<h2 style="font-family: "Trebuchet MS", Helvetica, sans-serif;
margin-top: 0px;margin-bottom: 3.5em;font-size: 1em;
color: darkblue;">Order Processing Division</h2>
<h4>Ordered by {signer_name}</h4>
<p style="margin-top:0em; margin-bottom:0em;">Email: {signer_email}</p>
<p style="margin-top:0em; margin-bottom:0em;">Copy to: {cc_name}, {cc_email}</p>
<p style="margin-top:3em;">
Candy bonbon pastry jujubes lollipop wafer biscuit biscuit. Topping brownie sesame snaps sweet roll pie.
Croissant danish biscuit soufflé caramels jujubes jelly. Dragée danish caramels lemon drops dragée.
Gummi bears cupcake biscuit tiramisu sugar plum pastry. Dragée gummies applicake pudding liquorice.
Donut jujubes oat cake jelly-o.
Dessert bear claw chocolate cake gummies lollipop sugar plum ice cream gummies cheesecake.
</p>
<!-- Note the anchor tag for the signature field is in white. -->
<h3 style="margin-top:3em;">Agreed: <span style="color:white;">**signature_1**/</span></h3>
</body>
</html>
"""
def make_envelope():
env = EnvelopeDefinition(email_subject='Please sign this document set')
doc = base64.b64encode(bytes(create_document('user@example.com', 'M Aaqib',
'user1@example.com', 'Aaqib'), "utf-8")).decode("ascii")
document = Document(document_base64=doc, name="Order acknowledgement", file_extension="html", document_id="1")
env.documents = [document]
signer = Signer(email='user@example.com', name='M Aaqib', recipient_id="1", routing_order="1")
cc = CarbonCopy(email='user1@example.com', name='Aaqib', recipient_id="2", routing_order="2")
sign_here = SignHere(anchor_string="**signature_1**", anchor_units="pixels",
anchor_y_offset="10", anchor_x_offset="20")
signer.tabs = Tabs(sign_here_tabs=[sign_here])
recipients = Recipients(signers=[signer], carbon_copies=[cc])
env.status = 'sent'
return env
def worker():
envelope_definition = make_envelope()
api_client = ApiClient()
api_client.host = BASE_PATH
api_client.set_default_header("Authorization", f"Bearer {ACCESS_TOKEN}")
envelopes_api = EnvelopesApi(api_client)
results = envelopes_api.create_envelope(ACCOUNT_ID, envelope_definition=envelope_definition)
envelope_id = results.envelope_id
return {"envelope_id": envelope_id}
def home(request):
return JsonResponse(worker())
但是,我得到的回应是这个错误:
ApiException at /
(401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'Cache-Control': 'no-cache', 'Content-Length': '153', 'Content-Type': 'application/json; charset=utf-8', 'X-DocuSign-TraceToken': '285033cb-cc24-4d43-a6e8-1231a89843c2', 'X-DocuSign-Node': 'DA4DFE71', 'Date': 'Sun, 20 Dec 2020 01:13:09 GMT', 'Vary': 'Accept-Encoding'})
HTTP response body: b'{"errorCode":"PARTNER_AUTHENTICATION_FAILED","message":"The specified Integrator Key was not found or is disabled. An Integrator key was not specified."}'
如果有人能在这方面指导我,我将非常感激
解决方案
所以,基本上我犯了一个非常愚蠢的错误。https://
我在基本路径中失踪了。
它应该是:BASE_PATH = 'https://demo.docusign.net/restapi'
代替:BASE_PATH = 'demo.docusign.net/restapi'
推荐阅读
- algorithm - 如何从相同数字列表中识别唯一不同的数字?
- reactjs - 从每个需要它的组件调用 React Apollo Hooks 有什么缺点,而不是将数据从父级传递给子级作为道具?
- javascript - Css 菜单下拉菜单
- swift - Mac OS:在开发时记住应用程序的安全和隐私选项
- python - 如何按要求显示输出?
- javascript - 给定 x 和 y 缩放图像
- csv - 在 Google 表格中打开 CSV 文件时,某些行被合并到一个单元格中
- c - =(赋值)的例子是右结合的
- linux - 汇编代码到 shell 代码:section .data 和 section .text 的顺序是什么?
- asp.net-core - ASP.NET Core MVC 中的标识脚手架问题