15 Sep 2021
06:58 AM
- last edited on
18 May 2023
05:15 AM
by
Michal_Gebacki
Hello,
I'm currently writing a python script to push an extention to several environments at the same time. Im not getting it to work. Im not getting it to upload the zip file, as the repsonse is 400 - Bad Request. Hoping someone here with some python experience knows what is wrong 🙂 Block of code not working follows:
import requests
import json
# ...
# Other blocks of code here that works fine
# ...
for tenant_id, token in zip(tenant_id_list, token_list):
url = "https://dtmanaged.com/e/" + tenant_id + "/api/config/v1/extensions?overrideAlerts=false"
payload = {'file': '@custom.python.ssl_cert_check.zip;type=application/x-zip-compressed'}
files = {'file': open('custom.python.ssl_cert_check.zip', 'rb')}
headers = {
'accept': 'application/json; charset=utf-8',
'Authorization': 'Api-Token ' + token,
'Content-Type': 'multipart/form-data'
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
print(response.status_code)
The zip file is in the same project as the Python file.
Solved! Go to Solution.
If you are using python already, may I suggest: https://github.com/dynatrace-oss/api-client-python
install with pip install dt
Then it is as simple as
from dynatrace import Dynatrace
dt = Dynatrace("<tenant_url>", "<apit_token>")
dt.extensions.post("D:/custom.remote.python.myextension.zip")