ここに私のコードがあります、
In [13]: test = """<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;">It’s hard to say what’s happening to us is something happy or not-and to what extend that particular thing is ‘a’ happy thing or not…..don’t believe it???</span><br style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;" /><span style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;">Well, when I was relaxing and indulging myself with watchin’ my favourite Chinese drama series, ‘square pegs’; my bro-in law asked me to buy him express bus ticket. And pastu, zuhadi called me up ajak aku gi KLIA hantar Mia g German..lgpun Arep pun nk ikut..I agreed..without knowin, that something will come up later…</span><br style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;" /><span style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;">I waited for Zuhadi at Jelatek LRT Putra Station..and after sometimes, he came and told me that Arep tak jd dtg….I knew it already bcoz I had already called Arep n he said that Mia had told(or wanted to tell) Zuhadi tak payah gi KLIA sbb die pun gi ngn KLIA Transit jer n better hantar duit dier yg zuhadi pinjam kat umh jer kan..</span><br style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;" /><span style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;">Since Arep pun tak dtg and Zuhadi pun seemed like havin another plan that was to go to Nini’s(Zuhadi’s fren who we mistakenly took her as Zuhadi gf) house(to get sumthin’). When we arrived at her house..but she wasn’t there( she was in Klang)..so I guess u know what we did-went there!</span><br style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;" /><span style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;">Along the way we talked bout our planning-Zuhadi get a job at AIA-congrats to him!!!..but me????..no what-so-ever plan yet!..we chatted..chat..chat..and then…..Gek..Gek…Gekk!..</span><br style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;" /><span style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;">We heard an awkward sound as we were passing a tol plaza…Then we realized that..THE RIGHT BACK TYRE HAD PUNCTURED!!!</span><br style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;" /><span style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;">IT took us almost an hour or so to change it!..we looked around for a car jack..but it was juz not there..luckily there was another car who broke down a long the road..so Zuhadi went and asked’em for that eject thingy..dunno what it called….Baru separuh gune benda alah tu..owner dia ckp yg kembara (keta abg Zuhadi) selalunye letak eject kat co-pilot punyer place..then we found it..hahahaha..tp punye le payah nk gune.sampai patah screw-driver yg Zuhadi gune!!..siap bleeding lg tangan die..kesian siot!!!</span><br style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;" /><span style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;">Last skali kitorg tukar tempat nk eject tuh..barulerr terangkat keta tuh!!!(hey..dun blame me!!!..i know nothin’ bout cars ok!)..we tought the ordeal was over, but nahhh!!!!..misery was so sad and tak sampai hat ink leave kitorg!!....Sampai nk mampus kitorg try nk bukak screw tayar yg pancit tu..tak gak bukak2!!!..then I went to the plaza tol and asked for peronda highway..pastu bl dh gi kat kat keta balik..barulerr ble bukak tayar pancit tuh!!!..AKHIRNYA!!!!!</span><br style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;" /><span style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;">So we continued our journey in meeting Nini n took her n Hazani(her fren) back to her house (Klang is where she’s havin her practicum). And I arrived home at almost 2a.m.</span><br style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;" /><span style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;">Well..why am I tellin’ this???...hahahha..you may think it was a terrible ordeal..bad experience..pengalaman pahit..but nahhh..i found it was very interesting, becoz we really had a good time—becoz if I were not there..Zuhadi will hav to face the prob alone and I was surely gonna be boring and depressing !!..i admit I didn’t do nothing much..but at least I was there to accompany him n jd penghibur tidak rasmi!..and if I didn’t go out wif him..i’d never face that kind of situation-b4 this..i never experienced tayar pancit!! hehehhee…</span><br style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;" /><span style="background-color: #1c1c1c; color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;">"And you know what????...i got it all in my digicam !"</span></div>
....: 2013-10-09 18:30:00.001000
....: O’ happy day!!!"""
In [14]: type(test)
Out[14]: str
In [15]: test.encode('utf-8')
そして、私はこのような出力を得ました、
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 209: ordinal not in range(128)
テストのために発生した上記のエラーは、既にエンコードされています。しかし、私は str を示す type キーワードを使用しています。私の質問は、文字列と ascii または (utf-8) ? の組み合わせです。指定された文字列がエンコードされているか、通常の文字列であることを確認する必要があります。エンコードされている場合は、何もしないか、エンコードを変換します。ありがとう...