简体   繁体   English

如何将请求同步到同步API?

[英]How to async request to a sync API?

I have built a REST API in Python using SQLAlchemy , Flask and Authlib ( Oauth framework). 我已经使用SQLAlchemyFlaskAuthlibOauth框架)在Python中构建了REST API。

在此处输入图片说明

This API runs over a Docker container which I have configured the SSL, CORS, permanent session ... 这个API运行在我配置了SSL,CORS,永久会话的Docker容器上...

When I try to request a token on the API using Axios in a React application, it works: 当我尝试在React应用程序中使用Axios在API上请求令牌时,它可以工作:

    axios({
      method: "post",
      url: `.../user/login`,
      data: {username, password}
    }).then(response => {
      ...
    }).catch(error => {
      ...
    })

But when I try to revoke this token making a Axios request to the logout middleware endpoint I receive Uncaught (in promise) Error: Request failed with status code 403 ( img ): 但是,当我尝试吊销此令牌向注销中间件端点发出Axios请求时,收到Uncaught (in promise) Error: Request failed with status code 403img ):

在此处输入图片说明

  axios({
    method: "post",
    url: `.../user/logout`,
    headers: {Authorization: `Bearer ${this.props.login.access_token}`},
  }).then(response => {
    ...
  }).catch({
    ...
  })

I don't understand it. 我不明白 If I issue a token and revoke using a application like Postman or Insonia , it works. 如果我发行令牌并使用PostmanInsonia之类的应用程序撤消 ,则该令牌有效。

How can I fix it ? 我该如何解决? Why is it happening ? 为什么会这样呢?

I research and found some threads, but I still have this issue: Async requests to a web service , Uncaught (in promise) Error: Request failed with status code 404 ... 我研究并发现了一些线程,但是仍然存在这个问题: 对Web服务的异步请求未捕获(承诺)错误:请求失败,状态码为404 ...

Obs ¹: I can't show the API source code for legal reasons with my employer 提示 ¹:由于法律原因,我无法向我的雇主显示API源代码

Obs ²: I'm assuming it's a async / sync problem, I not 100% sure Obs² :我假设这是一个异步/同步问题,我不确定100%

Usually, you get a Forbidden 403 response when you lack permissions to make the request. 通常,当您缺少发出请求的权限时,您会收到“禁止的403”响应。 I think this has something to do with CORS. 我认为这与CORS有关。 Can you please check the Network tab in your browser to make sure both the requests you make (through Postman and in the browser) look the same and if there's a OPTIONS request, what's the response? 您能否检查浏览器中的“网络”选项卡,以确保您(通过Postman和在浏览器中)发出的请求看起来都一样,如果有OPTIONS请求,响应是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM