From 8db8ab0a48daa5a5af441fbc990ba0ae435e5d2f Mon Sep 17 00:00:00 2001 From: TheLeo Date: Mon, 7 Oct 2024 13:45:13 +0000 Subject: [PATCH] fixed attachment issue --- ticket_transfer.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/ticket_transfer.py b/ticket_transfer.py index a233b86..468900f 100644 --- a/ticket_transfer.py +++ b/ticket_transfer.py @@ -31,6 +31,7 @@ def makeCall (target, verb, key, payload= None, files= None): return responseData except requests.exceptions.HTTPError as http_error: print(f'{RED}HTTP Error:{RESET}\n{http_error}') + pint(f'Reponse Content: {response.content}') raise except Exception as error: print(f'{RED}Error:{RESET}\n{error}') @@ -40,7 +41,7 @@ def makeCall (target, verb, key, payload= None, files= None): if files == None: response = requests.post(target, auth=(key, 'X'), json= payload) else: - response = requests.post(target, data= payload, auth=(key, 'X'), files= files) + response = requests.post(target, data=payload, auth=(key, 'X'), files= files) if response.status_code != 429: response.raise_for_status() responseData = response.json() @@ -52,6 +53,7 @@ def makeCall (target, verb, key, payload= None, files= None): return responseData except requests.exceptions.HTTPError as http_error: print(f'{RED}HTTP Error:{RESET}\n{http_error}') + print(f'Reponse Content: {response.content}') raise except Exception as error: print(f'{RED}Error:{RESET}\n{error}') @@ -182,12 +184,12 @@ for i, ticket in enumerate(ticketArray['results']): attachments = {} anim = ['◓', '◑', '◒', '◐'] ticketData = makeCall(sourceDom + f'/api/v2/tickets/{ticket["id"]}?include=conversations,requester', 'get', sourceKey) - if 'attachments' in ticket: - for x, attachment in enumerate(ticket['attachments']): + if 'attachments' in ticketData: + for attachment in ticketData['attachments']: if attachment.get('attachment_url'): - fileRes = requests.get(attachment.attachment_url) + fileRes = requests.get(attachment['attachment_url']) if fileRes.status_code == 200: - attachments[x] = (attachment['name'], fileRes.content) + attachments['attachments[]'] = (attachment['name'], fileRes.content) else: print(f'{RED}File Error:{RESET}\nFailed to download {attachment["name"]}') payload = { @@ -200,7 +202,7 @@ for i, ticket in enumerate(ticketArray['results']): 'description': ticketData["description"], 'source': ticketData["source"], } - newTicket = makeCall(destDom + '/api/v2/tickets', 'post', destKey, payload, files=attachments if attachments else None) + newTicket = makeCall(destDom + '/api/v2/tickets', 'post', destKey, payload, attachments if attachments else None) ## Gaterhing conversation history from ticketData, and then updating the ticket to include them in a private note if len(ticketData['conversations']) > 0: @@ -234,12 +236,4 @@ for i in range(5, 0, -1): print(f'Exiting in {i} seconds...') time.sleep(1) clear(1) -sys.exit(0) - - - - - - - - +sys.exit(0) \ No newline at end of file