【问题标题】:gmail api keeps changing the localhost address (python)gmail api不断更改本地主机地址(python)
【发布时间】:2020-12-18 04:14:38
【问题描述】:

我按照说明在我的应用程序中使用了 gmail oauth api。

在 Authorized redirect URIs 注册 url 似乎不起作用,因为 localhost 之后的数字似乎在每次运行中都会改变(请看图片)

问题是,当 Google 的 OAuth2 页面被调用时,redirect_uri 一直被设置为 http://localhost:/

image of the error

当我从 https://developers.google.com/gmail/api/quickstart/python 运行代码时出现此错误

【问题讨论】:

  • 您是否尝试仅将“localhost”添加到同意屏幕和凭据 redirect_uri?没有端口号?
  • 我试过了,但它说它是一个不完整的 URL

标签: python-3.x gmail-api


【解决方案1】:

quickstart.py 脚本的第 44 行,为服务器分配您将在凭据中使用的相同端口。

然后将语句改为

creds = flow.run_local_server(port=<your-credentials-port>)

参见google_auth_oauthlib.flow 模块。

【讨论】:

  • 这应该是与我运行应用程序的端口不同的端口吗?例如,我的本地前端服务器运行在 8080 上,我的本地后端服务器运行在 5000 上。当我在本地访问我的应用程序时,我转到 localhost:5000/[whatever]。当我按照您的描述使用端口 5000 时,出现此错误:OSError: [Errno 48] Address already in use
  • 使用不同的端口。它不能是正在使用的端口。任何未使用的端口都可以。这只是为了流动。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-28
  • 1970-01-01
  • 2016-04-21
  • 2020-12-10
  • 1970-01-01
  • 2017-05-13
  • 1970-01-01
相关资源
最近更新 更多