I have this duan.py file and this code:
elif str2 in email_content:
begin_encoding = email_content.find('Content-Transfer-Encoding: quoted-printable') + 51
retun_begin = email_content[begin_encoding:-1]
end_encoding = (retun_begin.find('Content-Type')) - 83
retun_end = retun_begin[0:end_encoding]
print('bắt đầu quoted')
print(retun_end)
print('456')
a = (quopri.decodestring(retun_end).decode('ISO-2022-JP'))
print (a)
The variable "retun_end" have value like this:
=1B$B?7$7$$J*7o$,EPO?$5$l$^$7$?$N$G!"$43NG\'$/$@$5$$!#=1B(B\r\n\r\n\r\n\r\n=1B$B<uIUF|=1B(B(Reception date)=1B$B!\'=1B(B2018-09-06\r\n\r\n=1B$BF@0U@hL>=1B(B(Customer name)=1B$B!\'%O%&%9%F%/%N3t<02q<R=1B(B -\r\n\r\n=1B$B<oJL=1B(B(Type): =1B$B9=3DB$=1B(BCAD=1B$BF~NO=1B(B\r\n\r\n=1B$BJ*7o=1B(B(Amount) 1 =1B$B7o=1B(B\r\n\r\n\r\n\r\n =1B$BJ*7o%3!<%I=1B(B(Project code)=1B$B!\'=1B(B10000002\r\n\r\n =1B$BJ*7oL>=1B(B(Project name)=1B$B!\'J!2,E!=1B(B\r\n\r\n =1B$B4uK>G<4|=1B(B(Deadline)=1B$B!\'=1B(B2018-09-07 AM\r\n\r\n\r\n\r\n=1B$BO"MmMs=1B(B(Contact)=1B$B!\'=1B(B =1B$BJV5Q$O#P#M=1B(B2=1B$B!\'=\r\n=1B(B00=1B$B:"$^$G$KAw$C$F$/$@$5$$!J$$$D$b$N$h$&$K:#F|Cf$K$*$/$l$k$J$i!"A0A=\r\nw$j$7$F$/$l$F$b$$$$$G$9!#!K=
But when i run it, it gave me an Error like this:
File "D:\odoo11test\custom_addons\Quy_Trinh_Du_An\models\duan.py", line 278, in read_email_function
a = (quopri.decodestring(retun_end).decode('ISO-2022-JP'))
UnicodeDecodeError: 'iso2022_jp' codec can't decode bytes in position 43-44: illegal multibyte sequence
Now, the problem that when i create new file py and have this code to test like this (test.py):
import quopri
a ='=1B$B?7$7$$J*7o$,EPO?$5$l$^$7$?$N$G!"$43NG\'$/$@$5$$!#=1B(B\r\n\r\n\r\n\r\n=1B$B<uIUF|=1B(B(Reception date)=1B$B!\'=1B(B2018-09-06\r\n\r\n=1B$BF@0U@hL>=1B(B(Customer name)=1B$B!\'%O%&%9%F%/%N3t<02q<R=1B(B -\r\n\r\n=1B$B<oJL=1B(B(Type): =1B$B9=3DB$=1B(BCAD=1B$BF~NO=1B(B\r\n\r\n=1B$BJ*7o=1B(B(Amount) 1 =1B$B7o=1B(B\r\n\r\n\r\n\r\n =1B$BJ*7o%3!<%I=1B(B(Project code)=1B$B!\'=1B(B10000002\r\n\r\n =1B$BJ*7oL>=1B(B(Project name)=1B$B!\'J!2,E!=1B(B\r\n\r\n =1B$B4uK>G<4|=1B(B(Deadline)=1B$B!\'=1B(B2018-09-07 AM\r\n\r\n\r\n\r\n=1B$BO"MmMs=1B(B(Contact)=1B$B!\'=1B(B =1B$BJV5Q$O#P#M=1B(B2=1B$B!\'=\r\n=1B(B00=1B$B:"$^$G$KAw$C$F$/$@$5$$!J$$$D$b$N$h$&$K:#F|Cf$K$*$/$l$k$J$i!"A0A=\r\nw$j$7$F$/$l$F$b$$$$$G$9!#!K='
print(quopri.decodestring(a).decode('ISO-2022-JP'))
It gives me the correct answer. How it can possible? Please help me :(
What I have tried:
I try it when i create new py file to test ( test.py ) and gave this code:
import quopri
a ='=1B$B?7$7$$J*7o$,EPO?$5$l$^$7$?$N$G!"$43NG\'$/$@$5$$!#=1B(B\r\n\r\n\r\n\r\n=1B$B<uIUF|=1B(B(Reception date)=1B$B!\'=1B(B2018-09-06\r\n\r\n=1B$BF@0U@hL>=1B(B(Customer name)=1B$B!\'%O%&%9%F%/%N3t<02q<R=1B(B -\r\n\r\n=1B$B<oJL=1B(B(Type): =1B$B9=3DB$=1B(BCAD=1B$BF~NO=1B(B\r\n\r\n=1B$BJ*7o=1B(B(Amount) 1 =1B$B7o=1B(B\r\n\r\n\r\n\r\n =1B$BJ*7o%3!<%I=1B(B(Project code)=1B$B!\'=1B(B10000002\r\n\r\n =1B$BJ*7oL>=1B(B(Project name)=1B$B!\'J!2,E!=1B(B\r\n\r\n =1B$B4uK>G<4|=1B(B(Deadline)=1B$B!\'=1B(B2018-09-07 AM\r\n\r\n\r\n\r\n=1B$BO"MmMs=1B(B(Contact)=1B$B!\'=1B(B =1B$BJV5Q$O#P#M=1B(B2=1B$B!\'=\r\n=1B(B00=1B$B:"$^$G$KAw$C$F$/$@$5$$!J$$$D$b$N$h$&$K:#F|Cf$K$*$/$l$k$J$i!"A0A=\r\nw$j$7$F$/$l$F$b$$$$$G$9!#!K='
print(quopri.decodestring(a).decode('ISO-2022-JP'))
It gives me correct answer. But in my duan.py, it doesn't. How can it possible? please help me :(