Why does my python script not getting executed?


i found this code in the forum which deletes old reports from testproject. Wanted to create a job for this which will regularly execute this script and delete data before i run out of storage.

import json
import requests
import datetime

def main():

    # Inset how many days backwards to keep 0 will result in all reports deleted
    days_to_keep_reports = 30
    # Inset API key here (replace with any API key)
    api_key = "MYKEY"

    # Shared headers (no change is required)
    headers = {"accept": "application/json",
               "Authorization": api_key,
               "Content-Type": "application/json"}
    # Get all project in the account by API key
    url = "https://api.testproject.io/v2/projects?_start=0"
    # Send request
    account_projects = requests.get(url, headers=headers)
    # print(account_projects)

    # Convert text response to JSON
    json_response = json.loads(account_projects.text)
    # Setting the time to keep reports backwards from now
    now = datetime.datetime.now() - datetime.timedelta(int(days_to_keep_reports))

    # Delete all reports of a project based on ids from the previous response
    for j in range(11): # repeat 10x so that it deletes more results
        print(str(j) + "...") 

        for i in json_response:
            project_id = i["id"]
            url = "https://api.testproject.io/v2/projects/" + project_id + "/reports"
            # Use all reports older than current time
            payload = '{"olderThan":"' + str(now) + '"}"'
            # Send request
            r = requests.delete(url, data=payload, headers=headers)
            # print(r)

# call function

The job has 1 test which has only 1 step:

where path is set to: C:\Users\MYUSERNAME\AppData\Local\Programs\Python\Python38\python.exe C:\Users\MYUSERNAME\Desktop\VSCode\Testproject\delete-rep.py

And when i execute this i get:

Any ideas what the problem might be?

Executing directly from vs code works.

This topic was automatically closed after 180 days. New replies are no longer allowed.