如何解决oauthlib.oauth2.rfc6749.errors.TokenExpiredError:

如何解决如何解决oauthlib.oauth2.rfc6749.errors.TokenExpiredError:

这就是我使用 requests_oauthlib import OAuth2Session 从 Salesforce 应用程序获取访问令牌的方法

auth_service.py

`from requests_oauthlib import OAuth2Session`

def token_saver(self,token=None):
        print("token to be saved",token)

def get_oauth2_requests(self,auth):
        print("OAuth2",auth)
        client_id = auth['oauth2']['client_id']
        client_secret = auth['oauth2']['client_secret']
        refresh_url = auth['oauth2']['refresh_url']
        token_client = auth['oauth2']['token']
        extra = {
            'client_id': client_id,'client_secret': client_secret,}
        token = {
            'access_token': 'eswfld123kjhn1v5423','refresh_token': token_client,'token_type': 'Bearer','expires_in': '-30'
        }
        client = OAuth2Session(client_id,token=token,auto_refresh_url=refresh_url,auto_refresh_kwargs=extra,token_updater=self.token_saver)
        return client

当它返回 oauth 2 客户端会话时。我们正在向 Salesforce 应用程序发出请求

触发器.py

if auth:
        dataParams["auth"] = auth_object

    print("Body",body)
    print(method)

    if body and method != "GET":
        dataParams["data"] = json.dumps(body)

    if content_type == "application/x-www-form-urlencoded":
        print('Sending application x-www-form-urlencoded')
        dataParams["data"] = body

    dataParams["headers"] = rest_auth.get_headers(auth,content_type)
    print("dataParams",dataParams)

    print("URL",url,"\nMethod",method,"\nDataparams",dataParams)

    response = client.request(method,**dataParams)

    return response.text

它适用于一些 oauth 2 应用程序,例如 google、asana、Microsoft,但是当它涉及到 salesforce 时,它​​给出了如下所示的错误

Traceback (most recent call last):
  File "F:\git-repos\unified\venv-unified\lib\site-packages\requests_oauthlib\oauth2_session.py",line 477,in request
    url,headers,data = self._client.add_token(
  File "F:\git-repos\unified\venv-unified\lib\site-packages\oauthlib\oauth2\rfc6749\clients\base.py",line 198,in add_token
    raise TokenExpiredError()
oauthlib.oauth2.rfc6749.errors.TokenExpiredError: (token_expired)

During handling of the above exception,another exception occurred:

Traceback (most recent call last):
  File "F:\git-repos\unified\venv-unified\lib\site-packages\flask\app.py",line 1950,in full_dispatch_request
    rv = self.dispatch_request()
  File "F:\git-repos\unified\venv-unified\lib\site-packages\flask\app.py",line 1936,in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "F:\git-repos\unified\unified/modules\main\portal.py",line 184,in portal
    response['result'] = rest(
  File "F:\git-repos\unified\unified/modules\main\trigger.py",line 318,in rest
    response = client.request(method,**dataParams)
  File "F:\git-repos\unified\venv-unified\lib\site-packages\requests_oauthlib\oauth2_session.py",line 504,in add_token
    raise TokenExpiredError()
oauthlib.oauth2.rfc6749.errors.TokenExpiredError: (token_expired)

我们正在从 token_saver() 方法获取令牌,如下所示

token to be saved {'access_token': '00D2v000002J66X!AQwAQFxIR.KkLSA74yI53A._b1Rp.uc1UXvBmpWP5erfHwULPj0yDLln0XBTXtfOcKCbPHlxGYTJWAqjMYwHH.JHKpIpgFqf','signature': 'O6MoT0xehqoZTvMi0wdwrD5fU+ITAXWixIf0ptt+oew=','scope': ['visualforce','custom_permissions','openid','refresh_token','wave_api','web','chatter_api','id','api','eclair_api','pardot_api','full'],'instance_url': 'https://ap15.salesforce.com','id': 'https://login.salesforce.com/id/00D2v000002J66XEAS/0052v00000f0e07AAA','issued_at': '1616182472230','refresh_token': '5Aep861dlMxAL.LhVRuNsLfAdWv0DjJVGBbZuLG8FqcTPokBCeMug96ABAgy7rQ.hAht.x5aTXCAzy5sMTnnLQd'}

我无法从 requests_oauthlib 或 request 中找出天气问题 任何帮助表示赞赏

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?