You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用DocuSign API JWT OAuth时遇super() must be type, not str错误求助

DocuSign JWT OAuth 调用错误:super() must be type, not str

问题详情

使用Swagger提供的DocuSign API进行JWT OAuth认证时,已实现获取JWT用户令牌的方法,但调用self.api_client.get_jwt_token(access_token)时返回错误:super() must be type, not str。已知DocuSign的ApiClient类定义为class ApiClient(object):,且类内部未错误调用super(),需分析问题原因及排查方向。

相关代码

class DocusignObj(object):
    def __init__(self, prefs):
        self.api_client = docusign_esign.ApiClient()

    def get_token(self):
        # Call request_jwt_user_token method
        try:
            token_response = self.api_client.request_jwt_user_token(
                                        client_id=self.DOCUSIGN_CLIENT_ID,
                                        user_id=self.DOCUSIGN_ACCOUNT_ID,
                                        oauth_host_name=self.DOCUSIGN_AUTH_SERVER,
                                        private_key_bytes=self.private_key,
                                        expires_in=28800,
                                        scopes=SCOPES)
        except ApiException as err:
            body = err.body.decode('utf8')
            if "consent_required" in body:
                consent_url = self.get_consent_url()
                webbrowser.open(consent_url)
                token_response = self.get_jwt_token()
        # access token returns is long string
        access_token = token_response.access_token
        # Save API account ID
        try:
            user_info = self.api_client.get_user_info(access_token)
        except TypeError as e:
            print(e)
            return
        accounts = user_info.get_accounts()
        api_account_id = accounts[0].account_id
        base_path = f'{accounts[0].base_uri}/restapi'
        self.json_token_info = {'access_token': access_token,
                                'api_account_id': api_account_id,
                                'base_path': base_path
                                }
        return self.json_token_info

原因分析

  1. 方法误用:DocuSign的ApiClient类中并无接收access_token作为参数的get_jwt_token方法。从代码逻辑看,你已通过request_jwt_user_token获取到令牌,此处调用get_jwt_token属于方法误用,传入字符串类型的access_token后触发内部类型错误。

  2. 实例状态异常:若self.api_client被意外覆盖为字符串类型(比如某处误将access_token赋值给该变量),调用其方法时会将字符串当作对象处理,进而触发super()调用的类型错误。

  3. SDK版本不兼容:不同版本的DocuSign SDK方法签名可能存在差异,若使用的版本中get_jwt_token方法的参数要求与你的调用方式不匹配,也可能引发此类错误。

排查思路

  1. 核对SDK方法定义:查阅当前使用的docusign_esign SDK文档,确认get_jwt_token方法的合法参数。实际流程中,获取access_token后应通过set_default_header将令牌设置到请求头:

    self.api_client.set_default_header("Authorization", f"Bearer {access_token}")
    
  2. 检查实例完整性:在调用get_jwt_token前添加打印语句,确认self.api_client的类型:

    print(type(self.api_client))  # 应输出<class 'docusign_esign.api_client.ApiClient'>
    

    排查代码中是否存在修改self.api_client的逻辑,确保其始终为ApiClient实例。

  3. 验证参数类型:确认access_token为字符串类型,同时检查get_jwt_token方法是否被自定义覆盖,导致参数要求变更。

  4. 调整SDK版本:尝试升级或降级docusign_esign SDK版本,排除版本兼容问题。

内容的提问来源于stack exchange,提问作者Ryan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 20:50:05