0

I have a curl command that works and gives me back the JSON. Curl command:

    curl -sS -k -L -H "Authorization: bearer <token>" -X GET https://IP:PORT/api/v1/namespaces

I tried with requestsand pycurl modules which I found in the other posts but no luck.

Can anyone help me with finding the equivalent in python???

0

1 Answer 1

1

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)
  • The -H switch behaviour is replicated by sending a header
  • The -L switch behaviour is replicated by specifying verify=False
  • The -sS and -k are about the behaviour of curl and not relevant here
  • The -X GET is replicated by using requests.get()
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it works, the token I had was also not correct. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.