Django中有Docusign的MaxRetryError

时间:2018-07-23 22:19:47

标签: django python-3.x docusignapi

我正在为我的公司开发一个Web应用程序。用户在我提供的表单中输入信息后,便会生成pdf表单(使用weasyprint),将客户的信息填写到必填字段中。但是,我需要将docusign的webapi集成到我的项目中。我已经弄乱了一些代码,并到达了下面的当前点:

def Signview(request):

    username = "myDocusignUsername"
    integrator_key = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    base_url = "https://demo.docusign.net/restapi"
    oauth_base_url = "account-d.docusign.com/oauth/auth?request_type=code&scope=signature&client_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&redirect_uri=http://localhost:8000/page/to/redirect/to"
    redirect_uri = "http://localhost:8000/page/to/redirect/to"
    private_key_filename = "createquote/keys/pKey.txt"
    user_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

    file_contents = open("path/to/mydoc.pdf", 'rb').read()

    envelope_definition = docusign.EnvelopeDefinition()
    envelope_definition.email_subject = 'My email subject'
    envelope_definition.email_blurb = 'My email blurb'

    doc = docusign.Document()
    base64_doc = base64.b64encode(file_contents).decode('utf-8')
    doc.document_base64 = base64_doc
    doc.name = "mydoc.pdf"
    doc.document_id = '1'
    envelope_definition.documents = [doc]

    signer = docusign.Signer()
    signer.email = loa.email
    signer.name = loa.ainame
    signer.recipient_id = '1'

    sign_here = docusign.SignHere()
    sign_here.document_id = '1'
    sign_here.page_number = '1'
    sign_here.recipient_id = '1'
    sign_here.x_position = '100'
    sign_here.y_position = '100'
    sign_here.scale_value = '0.5'

    tabs = docusign.Tabs()
    tabs.sign_here_tabs = [sign_here]
    signer.tabs = tabs

    recipients = docusign.Recipients()
    recipients.signers = [signer]
    envelope_definition.recipients = recipients

    envelope_definition.status = 'sent'

    auth_api = AuthenticationApi()
    envelopes_api = EnvelopesApi()

    try:
        login_info = auth_api.login(api_password='true', include_account_id_guid='true')
        assert login_info is not None
        assert len(login_info.login_accounts) > 0
        login_accounts = login_info.login_accounts
        assert login_accounts[0].account_id is not None

        base_url, _ = login_accounts[0].base_url.split('/v2')
        self.api_client.host = base_url
        docusign.configuration.api_client = self.api_client

        envelope_summary = envelopes_api.create_envelope(login_accounts[0].account_id, envelope_definition=envelope_definition)
        assert envelope_summary is not None
        assert envelope_summary.envelope_id is not None
        assert envelope_summary.status == 'sent'

        print("EnvelopeSummary: ", end="")
        pprint(envelope_summary)

    except ApiException as e:
        print("\nException when calling DocuSign API: %s" % e)
        assert e is None # make the test case fail in case of an API exception

    return HttpResponse({'sent'})

这基于位于此处的代码:https://github.com/docusign/docusign-python-client/blob/master/test/unit_tests.py,第129行至194行。

我想做的是将生成的文档(自动保存到我拥有的数据库中的模型中)以电子邮件形式发送,其中包含要使用Docusign的Python SDK签名的表格。但是,当我运行此代码并到达此特定视图时,出现以下错误:

Environment:


Request Method: GET
Request URL: http://localhost:8000/createquote/genloa/sign/

Django Version: 2.0.6
Python Version: 3.7.0
Installed Applications:
['createquote',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\urllib3\connection.py" in _new_conn
  171.                 (self._dns_host, self.port), self.timeout, **extra_kw)

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\urllib3\util\connection.py" in create_connection
  56.     for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\socket.py" in getaddrinfo
  748.     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):

During handling of the above exception ([Errno 11004] getaddrinfo failed), another exception occurred:

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\urllib3\connectionpool.py" in urlopen
  600.                                                   chunked=chunked)

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\urllib3\connectionpool.py" in _make_request
  343.             self._validate_conn(conn)

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\urllib3\connectionpool.py" in _validate_conn
  849.             conn.connect()

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\urllib3\connection.py" in connect
  314.         conn = self._new_conn()

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\urllib3\connection.py" in _new_conn
  180.                 self, "Failed to establish a new connection: %s" % e)

During handling of the above exception (<urllib3.connection.VerifiedHTTPSConnection object at 0x000000000678CD30>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed), another exception occurred:

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\django\core\handlers\exception.py" in inner
  35.             response = get_response(request)

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\django\core\handlers\base.py" in _get_response
  128.                 response = self.process_exception_by_middleware(e, request)

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\django\core\handlers\base.py" in _get_response
  126.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\wkstat\Desktop\Development\LNQuoteTool\createquote\views.py" in Signview
  125.      login_info = auth_api.login(api_password='true', include_account_id_guid='true')

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\docusign_esign\apis\authentication_api.py" in login
  388.             (data) = self.login_with_http_info(**kwargs)

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\docusign_esign\apis\authentication_api.py" in login_with_http_info
  472.                                         collection_formats=collection_formats)

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\docusign_esign\api_client.py" in call_api
  385.                                    _return_http_data_only, collection_formats, _preload_content, _request_timeout)

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\docusign_esign\api_client.py" in __call_api
  208.                                      _request_timeout=_request_timeout)

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\docusign_esign\api_client.py" in request
  408.                                         headers=headers)

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\docusign_esign\rest.py" in GET
  209.                             query_params=query_params)

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\docusign_esign\rest.py" in request
  188.                                               headers=headers)

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\urllib3\request.py" in request
  68.                                            **urlopen_kw)

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\urllib3\request.py" in request_encode_url
  89.         return self.urlopen(method, url, **extra_kw)

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\urllib3\poolmanager.py" in urlopen
  322.             response = conn.urlopen(method, u.request_uri, **kw)

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\urllib3\connectionpool.py" in urlopen
  667.                                 **response_kw)

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\urllib3\connectionpool.py" in urlopen
  667.                                 **response_kw)

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\urllib3\connectionpool.py" in urlopen
  667.                                 **response_kw)

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\urllib3\connectionpool.py" in urlopen
  638.                                         _stacktrace=sys.exc_info()[2])

File "C:\users\wkstat\appdata\local\programs\python\python37\lib\site-packages\urllib3\util\retry.py" in increment
  398.             raise MaxRetryError(_pool, url, error or ResponseError(cause))

Exception Type: MaxRetryError at /createquote/genloa/sign/
Exception Value: HTTPSConnectionPool(host='www.docusign_esign.net', port=443): Max retries exceeded with url: /restapi/v2/login_information?api_password=true&include_account_id_guid=true (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x000000000678CD30>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed'))

有人知道我在这里做错了吗?我真的迷路了,Docusign并没有从WebAPI的调用中提供指导。

提前谢谢!

1 个答案:

答案 0 :(得分:0)

这是最近为python API(https://github.com/docusign/docusign-python-client/issues/15)打开并解决的,但更改尚未发布。

无论哪种方式,由于要使用演示URL,因此您将需要像上面一样覆盖它。您遇到的特定问题是AuthenticationApi使用了错误的URL。您需要将其传递给api客户端:

auth_api = AuthenticationApi(api_client=api_client)