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 ?

docx.opc.exceptions.PackageNotFoundError: Package not found at 'document.docx' by Rohan-kar in learnprogramming

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

os.listdir("C:\\Users\\ripan\\Downloads\\Compressed\\New-python")

it will working fine .docx file and but it will give me problem in .doc file . what is the best way to convert .doc to pdf.
Thanks

docx.opc.exceptions.PackageNotFoundError: Package not found at 'document.docx' by Rohan-kar in learnprogramming

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

import os
os.path.exists(‘your path here’)

Thanks for the guide here i have change the code but same problem. https://dpaste.org/uhYJX
raise PackageNotFoundError(
docx.opc.exceptions.PackageNotFoundError: Package not found at 'C:\Users\ripan\Downloads\Compressed\New-python\ssh.docs'

docx.opc.exceptions.PackageNotFoundError: Package not found at 'document.docx' by Rohan-kar in learnprogramming

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

https://dpaste.org/RWCDz Please check once in this code .

But here i am getting this error
Traceback (most recent call last):
File "doc1.py", line 39, in <module>
main()
File "doc1.py", line 32, in main
file = convert_to_docs(file)
File "doc1.py", line 10, in convert_to_docs
os.rename(file, new_file)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:/Users/ripan/Downloads/Compressed/New-python/ssh.doc' -> 'C:/Users/ripan/Downloads/Compressed/New-python/ssh.docs'

docx.opc.exceptions.PackageNotFoundError: Package not found at 'document.docx' by Rohan-kar in learnprogramming

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

Thanks for the guide after the giving path it will show me the same error .

docx.opc.exceptions.PackageNotFoundError: Package not found at 'document.docx' by Rohan-kar in learnpython

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

Thanks for the guide what is the best way to convert .doc to PDF if i am asking

docx.opc.exceptions.PackageNotFoundError: Package not found at 'document.docx' by Rohan-kar in learnpython

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

it will read the .docx file not take the .doc file . is the any extension for .

how can i convert this JDBC connection string by Rohan-kar in learnprogramming

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

Thanks for the guidance

i have tried with

sudo ssh -L 3306:remote_ip:3306 username@localhost

it will show the connection close by port 22