python - 在 python 上为 Oauth2 设置安全的 https 连接
问题描述
我正在尝试使用 google people API 来自动在我们的工作电话上创建一些联系人。但是对于使用人员 API,我需要使用 OAuth 2,并且我正在使用以下代码。我转到授权 URL,获取授权响应,但是当我运行令牌行时出现错误:
InsecureTransportError: (insecure_transport) OAuth 2 MUST utilize https.
代码如下:
import json
with open(r'C:\Users\Pedro\Desktop\client_id.json') as abb:
ab = json.load(abb)
client_id = ab['installed']['client_id']
redirect_uri = ab['installed']['redirect_uris'][0]
client_secret = ab['installed']['client_secret']
from requests_oauthlib import OAuth2Session
scope = ['https://www.googleapis.com/auth/contacts']
oauth = OAuth2Session(client_id, redirect_uri=redirect_uri,
scope=scope)
authorization_url, state = oauth.authorization_url(
'https://accounts.google.com/o/oauth2/auth',
# access_type and prompt are Google specific extra
# parameters.
access_type="offline", prompt="select_account")
#authorization_response = input('Enter the full callback URL')
authorization_response = r'RESPONSE'
token = oauth.fetch_token(
'https://accounts.google.com/o/oauth2/token',
authorization_response=authorization_response,
# Google specific extra parameter used for client
# authentication
client_secret=client_secret,
)
我想我所要做的就是设置一个https服务器?但我试图找到 OAuth2 服务器的示例,我得到的只是人们告诉我禁用测试要求。我不想测试,我想运行 OAuth,这样我就可以在人员 API 上调用请求。
解决方案
尝试export OAUTHLIB_INSECURE_TRANSPORT=1
在终端拍摄。它应该工作。
推荐阅读
- apache-flink - 2 SideOutputs 行为的联合
- reactjs - 根据内容中的值重新排序 FlatList
- react-native - react-devtools 代理在 react native 与 expo 中没有任何联系
- python - 匹配选定区域的颜色
- hyperledger-fabric - 未能调用链代码契约,错误:事务返回失败:ReferenceError:bor 未定义
- unit-testing - 如何通过测试到达 catchError 运算符
- ios - SDK 版本问题。此应用更新是使用 iOS 12.1 SDK 构建的。自 2020 年 6 月 30 日起,iPhone 应用程序的更新必须使用 iOS 13 SDK 构建
- postgresql - Google Cloud Platform 中的 PostgreSQL 自动备份问题
- mysql - 如何更正 MySQL 多个 JOINS 查询中的列名值
- javascript - KonvaJS | 形状位置不正确