[英]Equivalent python code for curl command for https call
I have a curl command that works and gives me back the JSON. 我有一个curl命令可以正常工作,并且还给我JSON。 Curl command:
卷曲命令:
curl -sS -k -L -H "Authorization: bearer <token>" -X GET https://IP:PORT/api/v1/namespaces
I tried with requests
and pycurl
modules which I found in the other posts but no luck. 我尝试了在其他帖子中找到的
requests
和pycurl
模块,但是没有运气。
Can anyone help me with finding the equivalent in python??? 任何人都可以帮助我在python中找到等效项吗???
We can do this with requests like this: 我们可以这样处理:
import requests
header = {'Authorization': 'bearer <token>'}
resp = requests.get("https://IP:PORT/api/v1/namespaces",
headers = header,
verify=False)
print(resp.status_code)
print(resp.text)
-H
switch behaviour is replicated by sending a header -H
开关行为 -L
switch behaviour is replicated by specifying verify=False
verify=False
复制-L
开关行为 -sS
and -k
are about the behaviour of curl and not relevant here -sS
和-k
与卷曲行为有关,此处不相关 -X GET
is replicated by using requests.get()
requests.get()
复制-X GET
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.