本文介绍了如何解决错误:“unicodedecodeerror:'iso2022_jp'编解码器无法解码位置43-44中的字节:非法多字节序列”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有这个duan.py文件和这段代码: elif str2 > 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引用') print (retun_end) print ( ' 456')a =(quopri.decodestring(retun_end).decode(' ISO -2022-JP')) print (a) 变量retun_end的值如下: = 1B $ B?7 $ 7 $$ J * 7o $,EPO?$ 5 $ l $ ^ $ 7 $?$ N $ G!$ 43NG\'$ / $ @ $ 5 $$!#= 1B(B\r\\\\r\\\\r\\\\r\\\ = 1B $ B < uIUF | = 1B(B(接收 日期) = 1B $ B!\' = 1B(B2018 -09-06\r\\\\r\\\ = 1B $ BF @ 0U @ hL > = 1B(B(客户) name)= 1B $ B!\'%O%&%9%F%/%N3t < 02 q< R = 1B(B - \\\\\\\ = 1B $ B< oJL = 1B(B (类型): = 1B $ B9 = 3DB $ = 1B(BCAD = 1B $ BF~NO = 1B(B \\\\ = n = 1B $ BJ * 7o = 1B(B(金额) 1 = 1B $ B7o = 1B(B \\\ \\\\\\\\\ = 1B $ BJ * 7o% 3!<% I = 1B(B(项目)代码)= 1B $ B!\ ' = 1B(B10000002 \\\\\\\ n = 1B $ BJ * 7oL> = 1B(B(项目名称)= 1B $ B!\'J!2,E!= 1B(B \\\\\\ n = 1B $ B4uK> G< 4 | = 1B(B(截止日期)= 1B $ B!\'= 1B(B2018-09-07 AM \\\\\\\\\\\\\\\ \\ n = 1B $ BOMmMs = 1B(B(联系人)= 1B $ B!\'= 1B(B = 1B $ BJV5Q $ O#P#M = 1B(B2 = 1B $ B!\'= \r\\\ = 1B(B00 = 1B $ b:$ ^ $ G $卡奥$ C $ F $ / $ @ $ 5 $$Ĵ$$$ d $ b $ N $ H $&安培; $ķ :#F |比照$ $ķ* / $ $升$ķ$Ĵi的A0A = \r\\\w $Ĵ$ 7 $ F $ / $升$ F $ b $$$$$ G $ 9! #!K = 但是当我运行它时,它给了我一个像这样的错误: 文件D:\odoo11test \custom_addons \Quy_Trinh_Du_An\models\duan.py,第278行,在read_email_function a =(quopri.decodestring(retun_end).decode( 'ISO-2022-JP')) UnicodeDecodeError:'iso2022_jp'编解码器无法解码43-44位的字节:非法多字节序列 现在,日问题是,当我创建新文件py并让此代码进行测试时(test.py): import quopri a = ' = 1B $ B?7 $ 7 $$ J * 7o $,EPO ?$ 5 $升$ ^ $ 7个$?$ N $ G!$ 43NG\'$ / $ @ $ 5 $$!#= 1B(B\r\\\\r\\\\r\ n \\ n = 1B $ B< uIUF | = 1B(B(接待日期)= 1B $ B!\'= 1B(B2018-09-06 \\\\\\\ n = 1B $ BF @ 0U @ hL> = 1B(B(客户名称)= 1B $ B!\'%O%&%9%F%/%N3t< 02q< R = 1B(B -\ \ n \\ n = 1B $ B< oJL = 1B(B(类型):= 1B $ B9 = 3DB $ = 1B(BCAD = 1B $ BF~NO = 1B(B \\ n) \\\ n = 1B $ BJ * 7o = 1B(B(金额)1 = 1B $ B7o = 1B(B \\\\\\\\\\\\\\\\\\\ \\ n = 1B $ BJ * 7o%3!<%I = 1B(B(项目代码)= 1B $ B!\'= 1B(B10000002 \\\\\ = BJ * 7oL> = 1B(B(项目名称)= 1B $ B!\'J!2,E!= 1B(B \\\\\\ = = B $ B4uK> G< 4 |!= 1B(B(截止时间)= 1B $ B \'= 1B(B2018-09-0 7 AM \\\\\\\\\\\\ = = $ 1B $ BOMmMs = 1B(B(联络)= 1B $ B!\'= 1B( B = 1B $ BJV5Q $ O#P#M = 1B(B2 = 1B $ B!\'= \\\\ = n = 1B(B00 = 1B $ B:$ ^ $ G $ KAw $ C $ F $ / $ @ $ 5 $$Ĵ$$$ d $ b $ N $ H $&安培; $ K:!#F |比照$ $ķ* / $ $升$ķ$Ĵi的A0A = \r \ nw $ j $ 7 $ F $ / $ l $ F $ b $$$$$ G $ 9!#!K =' print (quopri.decodestring(a).decode(' ISO-2022-JP')) 它给了我正确的答案。怎么可能?请帮帮我:( 我尝试了什么: 我尝试创建新的py文件来测试(test.py)并给出这段代码: import quopri a = ' = 1B $ B?7 $ 7 $$ J * 7o $,EPO?$ 5 $升$ ^ $ 7个$?$ N $ G!$ 43NG\'$ / $ @ $ 5 $$!#= 1B(B\r\\\\r\\\\r\\\\ r \ n = 1B $ B< uIUF | = 1B(B(接待日期)= 1B $ B!\'= 1B(B2018-09-06 \\\\\\\ = BF @ 0U @ hL> = 1B(B(客户名称)= 1B $ B!\'%O%&%9%F%/%N3t< 02q< R = 1B(B -\\ n \\\ n = 1B $ B< oJL = 1B(B(类型):= 1B $ B9 = 3DB $ = 1B(BCAD = 1B $ BF~NO = 1B(B \\\\ \\\ = 1B $ BJ * 7o = 1B(B(金额)1 = 1B $ B7o = 1B(B \\\\\\ n = 1B $ BJ * 7o%3!<%I = 1B(B(项目代码)= 1B $ B!\'= 1B(B10000002 \\\\\ n = 1B $ BJ * 7oL> ; = 1B(B(项目名称)= 1B $ B!\'J!2,E!= 1B(B \\\\ \\\ = 1B $ B4uK> G< 4 | = 1B(B(截止日期)= 1B $ B!\'= 1B(B2018-09-07 AM \\\\\\\\\\ r \\\ n = 1B $ BOMmMs = 1B(B(联系人)= 1B $ B!\'= 1B(B = 1B $ BJV5Q $ O#P#M = 1B(B2 =图1B $ b \'= \r\\\ = 1B(B00 = 1B $ b:!$ ^ $ G $卡奥$ C $ F $ / $ @ $ 5 $$Ĵ$$$ d $ b $ N $ H $&安培; $ K:#F |比照$ $ķ* / $ $升$ķ$Ĵi的A0A = \r\\\w $Ĵ$ 7 $ F $ / $升$ F $ b! $$$$$ G $ 9!#!K =' print (quopri.decodestring(a).decode(' ISO-2022-JP')) 它给出了我正确答案。但是在我的duan.py中,它没有。怎么可能?请帮帮我:(解决方案 B?7 7 J * 70 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 sequenceNow, the problem that when i create new file py and have this code to test like this (test.py):import quopria ='=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 quopria ='=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 :( 解决方案 B?77J*7o 这篇关于如何解决错误:“unicodedecodeerror:'iso2022_jp'编解码器无法解码位置43-44中的字节:非法多字节序列”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-22 05:47