简体   繁体   中英

curl get request with python3

I am trying to execute a curl GET request with python3 the request is:
curl -k -X GET -H "X-Some-Token: s.ggt5gvf344f"https://ip.address:port/v1/path/path

how it can be implemented?

import requests

url = "https://ip.address:port/v1/path/path"

payload={}
headers = {
    'X-Some-Token': 's.ggt5gvf344f'
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

or you can try http.client library which is much faster than requests

import http.client

conn = http.client.HTTPSConnection("ip.address", port)
payload = ''
headers = {
  'X-Some-Token': 's.ggt5gvf344f'
}
conn.request("GET", "/v1/path/path", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM