Invoke Octopus REST apis using Python

external
usability
(Falcon Francis) #1

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

apiKey = ‘API-XXXXXXXXXXXX’
header = {“Content-Type”: “application/json”, “X-Octopus-ApiKey”: apiKey}
octopus_url = “https://deploy.mycompanyname.com/Octopus/api/tasks/ServerTasks-168240/details

s = requests.Session()
s.headers.update(header)
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))
else:
print(‘Success’)

I get too many errors like
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=‘deploy.mycompanyname.com’, 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:

(Daniel Fischer) #3

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,
Daniel

1 Like
(Falcon Francis) #4

Thank you,

It worked.

(system) closed #5

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