Python Forum
decode base64 with python give error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
decode base64 with python give error
#4
Oke I will post all my code here, can you check it for me, please.
import imaplib
import base64
import chardet
import quopri
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
mail_st = "[email protected]"
pass_st = "password"
imap = imaplib.IMAP4_SSL("mail.eplatform.vn",993)
imap.login(mail_st,pass_st)
        #quét mail
imap.select("INBOX")

status, response = imap.search(None,'(UNSEEN)')
unread_msg_nums = response[0].split()

        #in tổng mail chưa đọc
print(len(unread_msg_nums))

        #bắt đầu đọc mail
for e_id in unread_msg_nums:

    _, response = imap.fetch(e_id, '(RFC822)')
    print('bắt đầu in mail')
    content_email = str(response[0][1])
    print (content_email)
    str1 = 'Content-Transfer-Encoding: base64'
    str2 = 'Content-Transfer-Encoding: quoted-printable'
    str3 = 'Content-Transfer-Encoding: 8bit'

            #chia câu lệnh if để chạy mail

    if str1 in content_email:
        print('test thử coi sao')
        aaa= '5paw44GX44GE54mp5Lu244GM55m76Yyy44GV44KM44G+44GX44Gf44Gu44Gn44CB44GU56K66KqN\r\n44GP44Gg44GV44GE44CCCQ0KCQ0K5Y+X5LuY5pel77yaMjAxOOW5tDA55pyIMjDml6UJDQrlvpfm\r\nhI/lhYjlkI3vvJrjg4/jgqbjgrnjg4bjgq/jg47moKrlvI/kvJrnpL4gLQkNCuaLheW9k+iAhe+8\r\nmiBpbWFuaXNoaQkNCueoruWIpTog5qeL6YCgQ0FE5YWl5YqbCQ0K54mp5Lu2IDEg5Lu2CQ0KDQoJ\r\n54mp5Lu244Kz44O844OJ77yaMTAwMDAwNTANCgnnianku7blkI3vvJrlpKfkuYXkv53kuK0xMeWP\r\ntw0KCeeZuuazqOWFg++8mumWouilv+ODm+ODvOODoA0KCeeZuuazqOWGheWuue+8muioguatow0K\r\nCeW4jOacm+e0jeacn++8mjIwMTgtMDktMjEgQU0NCg0K6YCj57Wh5qyE77yaDQo='
 
        data1 = base64.b64decode(aaa)
        print(data1)

        begin_encoding = content_email.find('Content-Transfer-Encoding: base64') + 41
        retun_begin = content_email[begin_encoding:-1]
        end_encoding = (retun_begin.find('Content-Type')) - 38
        retun_end = retun_begin[0:end_encoding]
        print('bắt đầu base64')
        print (type(retun_end))
        print(retun_end)
        if retun_end:
            data = base64.b64decode(retun_end)
            print(data)
You can change email and pw of your, and send some mail in japanese language to this mail. I suggest sending mail by Gmail, remember that my problem is about decode to Japanese language

You can get this content to test just like my code ( sending by Gmail to this mail in your code )
新しい物件が登録されましたので、ご確認ください。	
	
受付日:2018年09月20日	
得意先名:ハウステクノ株式会社 -	
担当者: imanishi	
種別: 構造CAD入力	
物件 1 件	

	物件コード:10000050
	物件名:大久保中11号
	発注元:関西ホーム
	発注内容:訂正
	希望納期:2018-09-21 AM

連絡欄:	
Reply


Messages In This Thread
decode base64 with python give error - by thailq - Sep-20-2018, 06:51 AM
RE: decode base64 with python give error - by thailq - Sep-24-2018, 12:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Decode string ? JohnnyCoffee 1 830 Jan-11-2023, 12:29 AM
Last Post: bowlofred
  UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 error from Mysql call AkaAndrew123 1 3,465 Apr-28-2021, 08:16 AM
Last Post: AkaAndrew123
  JSON Decode error when using API to create dataframe Rubstiano7 4 2,961 Jan-11-2021, 07:52 PM
Last Post: buran
  how to encode and decode same value absolut 2 2,360 Sep-08-2020, 09:46 AM
Last Post: TomToad
  python-resize-image unicode decode error Pedroski55 3 3,500 Apr-21-2020, 10:56 AM
Last Post: Pedroski55
  struct.decode() and '\0' deanhystad 1 3,237 Apr-09-2020, 04:13 PM
Last Post: TomToad
  download base64 email attachment cferguson 3 4,739 Feb-25-2020, 06:50 PM
Last Post: cferguson
  Getting decode error. shankar 8 10,405 Sep-20-2019, 10:05 AM
Last Post: tinman
  Post JSON from python to PHP don't give expected result pgagnebin 1 3,762 Sep-04-2019, 10:29 PM
Last Post: micseydel
  Base64 to retrieve message JonasH 0 1,660 Jul-22-2019, 04:00 PM
Last Post: JonasH

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020