cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Uploading extention.zip through Python API script

marius_duns
Visitor

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.  

1 REPLY 1

david_lopes
Dynatrace Mentor
Dynatrace Mentor

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")



Featured Posts