oracle sql query and export excel and send email not shown persian and shown as question mark pandas python

Viewed 18

oracle sql query and export excel and send email not shown persian and shown as question marks

  connection = cx_Oracle.connect(user_db,password_db,dsn_tns)
  df = pd.read_sql(query,con=connection)
  attach_file_name = filename+'_'+timestr+'.xlsx'
  df.to_excel(attach_file_name,sheet_name="report",encoding="utf-8",engine='xlsxwriter')
  msg.attach(MIMEText(body,'plain'))
  attach_file = open(attach_file_name,'rb')
  payload = MIMEBase('application','octate-stream')
  payload.set_payload((attach_file).read())
  encoders.encode_base64(payload)
  payload.add_header('Content-Disposition',"attach_file; filename= "+attach_file_name)
  msg.attach(payload)
1 Answers

it is solved by reading query by encoding utf-8 from cx_orcale and change the engine of excel writer to xlswriter and set encoding

con = cx_Oracle.connect(user_db,password_db,dsn_tns,encoding="UTF-8")
df = pd.read_sql(indict.datasources.Query, con=con)
df.to_excel(attach_file_name, sheet_name="report", encoding="utf-8", engine='xlsxwriter')
Related