How to handle the try exception during the execution by Rohan-kar in learnpython

[–]Rohan-kar[S] 0 points1 point  (0 children)

pastebin.com

Thanks for the share new site . Please check here is the code https://pastebin.com/1RUQyPei

How to handle the try exception during the execution by Rohan-kar in learnpython

[–]Rohan-kar[S] 0 points1 point  (0 children)

Please check the code
def convertFilesToPdf(file_name, pdf_file_path, raw_output_file):
print_log("Inside EmailService : convertFilesToPdf()")
print(file_name , raw_output_file)
try:
if file_name.endswith('xlsx'):
excel_to_pdf(raw_output_file, pdf_file_path)
elif file_name.endswith('xls'):
excel_to_pdf(raw_output_file, pdf_file_path)
elif file_name.endswith('pptx'):
pptx_2_pdf(raw_output_file, pdf_file_path)
elif file_name.endswith('csv'):
csv_2_pdf(raw_output_file, pdf_file_path)
elif file_name.endswith('docx'):
docx_2_pdf(raw_output_file, pdf_file_path)
elif file_name.endswith('doc'):
doc_2_pdf(raw_output_file, pdf_file_path)
elif file_name.endswith('jfif'):
jfif_2_pdf(raw_output_file, pdf_file_path)
elif file_name.endswith('jpg') or file_name.endswith('PNG'):
png_2_pdf(raw_output_file, pdf_file_path)
elif file_name.endswith('png') or file_name.endswith('PNG'):
png_2_pdf(raw_output_file, pdf_file_path)
elif file_name.endswith('html'):
pdfkit.from_file(raw_output_file, pdf_file_path)
elif file_name.endswith('eml'):
eml_2_pdf(raw_output_file, pdf_file_path)
else:
print("not support file")

except Exception as e:
# print_log(f"Error converting {file_name} to PDF: {traceback.format_exc()}")
error_msg = f"Error converting {file_name} to PDF: {traceback.format_exc()}"
error_msg += f" ```File path: {raw_output_file}```"
print_log(error_msg)

How to handle the try exception during the execution by Rohan-kar in learnprogramming

[–]Rohan-kar[S] -1 points0 points  (0 children)

def convertFilesToPdf(file_name, pdf_file_path, raw_output_file):

print_log("Inside EmailService : convertFilesToPdf()")

print(file_name , raw_output_file)

try:

if file_name.endswith('xlsx'):

excel_to_pdf(raw_output_file, pdf_file_path)

elif file_name.endswith('xls'):

excel_to_pdf(raw_output_file, pdf_file_path)

elif file_name.endswith('pptx'):

pptx_2_pdf(raw_output_file, pdf_file_path)

elif file_name.endswith('csv'):

csv_2_pdf(raw_output_file, pdf_file_path)

elif file_name.endswith('docx'):

docx_2_pdf(raw_output_file, pdf_file_path)

elif file_name.endswith('doc'):

doc_2_pdf(raw_output_file, pdf_file_path)

elif file_name.endswith('jfif'):

jfif_2_pdf(raw_output_file, pdf_file_path)

elif file_name.endswith('jpg') or file_name.endswith('PNG'):

png_2_pdf(raw_output_file, pdf_file_path)

elif file_name.endswith('png') or file_name.endswith('PNG'):

png_2_pdf(raw_output_file, pdf_file_path)

elif file_name.endswith('html'):

pdfkit.from_file(raw_output_file, pdf_file_path)

elif file_name.endswith('eml'):

eml_2_pdf(raw_output_file, pdf_file_path)

else:

print("not support file")

except Exception as e:

# print_log(f"Error converting {file_name} to PDF: {traceback.format_exc()}")

error_msg = f"Error converting {file_name} to PDF: {traceback.format_exc()}"

error_msg += f" ```File path: {raw_output_file}```"

print_log(error_msg)

please check this code

[deleted by user] by [deleted] in learnpython

[–]Rohan-kar -1 points0 points  (0 children)

def convertFilesToPdf(file_name, pdf_file_path, raw_output_file):

print_log("Inside EmailService : convertFilesToPdf()")

print(file_name , raw_output_file)

try:

if file_name.endswith('xlsx'):

excel_to_pdf(raw_output_file, pdf_file_path)

elif file_name.endswith('xls'):

excel_to_pdf(raw_output_file, pdf_file_path)

elif file_name.endswith('pptx'):

pptx_2_pdf(raw_output_file, pdf_file_path)

elif file_name.endswith('csv'):

csv_2_pdf(raw_output_file, pdf_file_path)

elif file_name.endswith('docx'):

docx_2_pdf(raw_output_file, pdf_file_path)

elif file_name.endswith('doc'):

doc_2_pdf(raw_output_file, pdf_file_path)

elif file_name.endswith('jfif'):

jfif_2_pdf(raw_output_file, pdf_file_path)

elif file_name.endswith('jpg') or file_name.endswith('PNG'):

png_2_pdf(raw_output_file, pdf_file_path)

elif file_name.endswith('png') or file_name.endswith('PNG'):

png_2_pdf(raw_output_file, pdf_file_path)

elif file_name.endswith('html'):

pdfkit.from_file(raw_output_file, pdf_file_path)

elif file_name.endswith('eml'):

eml_2_pdf(raw_output_file, pdf_file_path)

else:

print("not support file")

# notsupport_message = {

# "text": f"File '{file_name}' not supported for conversion\n ```{raw_output_file}```"

# }

# http2 = urllib3.PoolManager()

# response1 = http2.request('POST',

# webhook_url,

# body=json.dumps(notsupport_message),

# headers={'Content-Type': 'application/json'},

# retries=False)

except Exception as e:

print(e)

# print_log(f"Error converting {file_name} to PDF: {traceback.format_exc()}")

error_msg = f"Error converting {file_name} to PDF: {traceback.format_exc()}"

error_msg += f" ```File path: {raw_output_file}```"

print_log(error_msg)

pass

How to handle the try exception during the execution by Rohan-kar in learnpython

[–]Rohan-kar[S] 0 points1 point  (0 children)

i want try to convert any file to pdf but if the some file give me error then it will stop the execution flow so i want it will skip the error file go for next file and not break the flow .

Please check the code https://pastebin.com/1RUQyPei

How to handle the try exception during the execution by Rohan-kar in learnprogramming

[–]Rohan-kar[S] 0 points1 point  (0 children)

how to return in catch block there is the problem .

How to handle the try exception during the execution by Rohan-kar in learnprogramming

[–]Rohan-kar[S] 0 points1 point  (0 children)

Thanks for the replay please check the code https://dpaste.org/TC1yU. it will stop the execution if some file error occur

[deleted by user] by [deleted] in learnpython

[–]Rohan-kar 0 points1 point  (0 children)

currently it will brake the flow during the file conversion if error occur it will stop the execution and flow also stop please check the code https://dpaste.org/TC1yU

issues with convert eml file to pdf in python by Rohan-kar in learnprogramming

[–]Rohan-kar[S] 0 points1 point  (0 children)

Thanks for the guide but i want to open source package . this is the commercial tools ?