首页 > 解决方案 > 如何在 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'))

标签: pythonjsonpython-3.xpython-requests

解决方案


推荐阅读