python - 如何在 Python 中连接到这个 curl 字符串?
问题描述
我正在尝试连接到 Python 中名为 knowbe4 的应用程序。但是,我不知道如何将 curl 字符串转换为 python 请求。
这是卷曲字符串:
curl -k -X GET 'https://us.api.knowbe4.com' -H 'Authorization: Bearer 454yrghrtwehsthvNPXM'
这是我的代码:
import json
import requests
from config import configs
from exceptions import ConfigurationError, HTTPError
url='https://us.api.knowbe4.com'
t='454yrghrtwehsthvNPXM'
h={'Authorization': 'Bearer {0}'.format(t)}
resp = requests.get(url, headers=h, verify=False)
当我运行它时,什么也没有发生。难道我做错了什么?我是 api 调用的新手,所以任何信息都会有所帮助。
我得到的错误:
NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00050>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'))
解决方案
推荐阅读
- regex - 当任何字符串至少包含三个字符并且 + 号被最少三个字符包围时匹配的正则表达式
- python - Tkinter 将图像放入框架,背景
- ats - 在堆栈上分配数据类型
- c - 检查数组中的数字是否具有公因数的省时方法?
- html - 折叠后我的导航栏不会将项目显示为列表
- excel - 向此 VBA 添加超链接
- c++ - 如何确定两个字符串是否同构?
- java - 按子值(名称)搜索 Firebase,填充匹配名称列表并将意图添加到该列表
- keyboard - 是一种将 Notepad++ 配置为使用 Intellij 键盘映射的方法吗?
- docker - 如何从 docker compose 获取 redis 地址?