Downloading form

Hello Team,

I am writing a python script to automate some checks. For that I need to download the submitted form from the change ticket and then use the data from the downloaded file to do comparison. I would need the form in json format.
Please check the below code and suggest:

from typing import Any, Dict, Tuple
import json
import requests
import getpass
from opscli.core import kubernetes
from opscli.core import utils
from opscli.core.base_logger import logger
from opscli.core.console import console
from opscli.config import jcloud_env

from rich.table import Table

# Jira credentials and base URL
JIRA_USERNAME = 'bhatia@xxx.xxx'
JIRA_API_TOKEN = 'xxxxxxxxxxxxxxxxxxxxxxx'
JIRA_BASE_URL = '[https://paragon-automation.atlassian.net](https://paragon-automation.atlassian.net/)'

def prod_push_post_validation(ticket_number):

# Create a session and set basic authentication
session = requests.Session()
session.auth = (JIRA_USERNAME, JIRA_API_TOKEN)

# Get the Jira issue details to retrieve attachments
issue_url = f"{JIRA_BASE_URL}/rest/api/2/issue/{ticket_number}"
response = session.get(issue_url)
issue_data = response.json()

if 'fields' in issue_data and 'attachment' in issue_data['fields']:
attachments = issue_data['fields']['attachment']

# After fetching attachments
print("All Attachments:", [attachment['filename'] for attachment in attachments])

# Filter attachments with file names starting with "application" and random characters
filtered_attachments = [attachment for attachment in attachments if attachment['filename'].endswith('Applications')]

print("Issue URL:", issue_url)
print("Filtered Attachments:", [attachment['filename'] for attachment in filtered_attachments])

if filtered_attachments:
for attachment in filtered_attachments:
attachment_id = attachment['id']
attachment_name = attachment['filename']

# Download the attachment
download_url = f"{JIRA_BASE_URL}/secure/attachment/{attachment_id}/{attachment_name}"
response = session.get(download_url)

if response.status_code == 200:
with open(attachment_name, 'wb') as file:
file.write(response.content)
print(f"Downloaded: {attachment_name}")
else:
print(f"Failed to download: {attachment_name}")
else:
print("No matching attachments found.")
else:
print(f"Unable to retrieve attachment data for issue {ticket_number}.")

# Close the session
session.close()

This is being called like this:

@kubernetes_app.command("post_validation")
def prod_push_post_validation(
ticket_number: Annotated[str, typer.Option(
case_sensitive=False,
help="Enter the Jira Service Management change ticket number"
)]
) -> None:
post_push_check.prod_push_post_validation(
ticket_number=ticket_number
)

Output -

All Attachments: ['2023-11-16 1159 - Actions.pdf', '2023-11-16 1159 - Applications.pdf']
Issue URL: https://paragon-automation.atlassian.net/rest/api/2/issue/JSMSRE-15
Filtered Attachments: []
No matching attachments found.

Please suggest what is missing here.