如何在Python中连接到此curl字符串?

2024-10-01 09:17:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试连接到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'))

Tags: 字符串fromhttpsimportcomapiurlcurl