Invoke Octopus REST apis using Python

Hi Team,

I am trying to call Octopus REST API from Python.
Can someone help me to correct my script.
I am new to Python.
This is the script I use. (It doesnt work)

import json
import requests

header = {“Content-Type”: “application/json”, “X-Octopus-ApiKey”: apiKey}
octopus_url = “

s = requests.Session()
resp = s.get(octopus_url, headers={“Content-Type”: “application/json”, “X-Octopus-ApiKey”: apiKey})

if resp.status_code != 200:
print('error: ’ + str(resp.status_code))

I get too many errors like
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=‘’, port=443): Max retries exceeded with url: /Octopus/api/tasks/ServerTasks-168240/details (Caused by SSLError(SSLCertVerificationError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)’)))
During handling of the above exception, another exception occurred:

Hi @Falcon_Francis ,

Thanks for getting in touch! I had a quick look and I believe this is due to the self signed certificate that Octopus uses. As a quick workaround, you should be able to edit your s.get() to include a verify=false flag. This should skip the SSL verification / error and return the expected API resource.

This is the simplest option but perhaps not the most secure as stated in the below StackOverflow links. There are more secure options available but the verify=false flag is a quick workaround to identify the issue and get your script working.

Also, if you are wondering why Octopus uses self-signed certificates, we have a blog post explaining the choice.

Would you be able to try this and let me know if it resolves your issue?

If you have any further thoughts or questions on this, please don’t hesitate to let me know.

Best regards,

1 Like

Thank you,

It worked.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.