From 1f68f229257c2a592290da60151d800a12d2cd7d Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 10 Nov 2019 11:54:45 +0000 Subject: [PATCH] More debug --- content.py | 4 +++- daemon.py | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/content.py b/content.py index ba3f96e6..ede77d59 100644 --- a/content.py +++ b/content.py @@ -481,11 +481,13 @@ def saveMediaInFormPOST(mediaBytes,baseDir: str, \ fd.close() return filename,attachmentMediaType -def extractTextFieldsInPOST(postBytes,boundary) -> {}: +def extractTextFieldsInPOST(postBytes,boundary,debug: bool) -> {}: """Returns a dictionary containing the text fields of a http form POST The boundary argument comes from the http header """ msg = email.parser.BytesParser().parsebytes(postBytes) + if debug: + print('DEBUG: POST arriving '+msg.get_payload(decode=True).decode('utf-8')) messageFields=msg.get_payload(decode=True).decode('utf-8').split(boundary) fields={} # examine each section of the POST, separated by the boundary diff --git a/daemon.py b/daemon.py index dfb4e5a2..dc05778c 100644 --- a/daemon.py +++ b/daemon.py @@ -2652,12 +2652,29 @@ class PubServer(BaseHTTPRequestHandler): # in Python 3.8/3.10 # Instead we use the multipart mime parser from the email module postBytes=self.rfile.read(length) + if self.server.debug: + print('DEBUG: extracting media from POST') mediaBytes,postBytes=extractMediaInFormPOST(postBytes,boundary,'attachpic') + if self.server.debug: + if mediaBytes: + print('DEBUG: media was found. '+str(len(mediaBytes))+' bytes') + else: + print('DEBUG: no media was found in POST') filename,attachmentMediaType= \ saveMediaInFormPOST(mediaBytes,self.server.baseDir, \ nickname,self.server.domain, \ self.server.debug,None) - fields=extractTextFieldsInPOST(postBytes,boundary) + if self.server.debug: + if filename: + print('DEBUG: POST media filename is '+filename) + else: + print('DEBUG: no media filename in POST') + fields=extractTextFieldsInPOST(postBytes,boundary,self.server.debug) + if self.server.debug: + if fields: + print('DEBUG: text field extracted from POST '+str(fields)) + else: + print('WARN: no text fields could be extracted from POST') # process the received text fields from the POST if not fields.get('message') and not fields.get('imageDescription'):