Python Forum
python3 decoding problem but python2 OK
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python3 decoding problem but python2 OK
#1
Hello,
I am facing a problem while decoding unicode urlencoded data in python3 but in python 2 working fine.My Python2 and
Python3 code with output is attached below.
Any suggestion is highly appreciable.

Regards
Mesbah


#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import urllib
import codecs
import locale

str1='%09%B0%09%BE%09%9C%09%A7%09%BE%09%A8%09%C0%09%B0%00+%09%95%09%C1%09%DC%09%BF%09%B2%00+%09%9A%09%CC%09%B0%09%BE%09%B8%09%CD%09%A4%09%BE%09%DF%00+%09%9B%09%C1%09%B0%09%BF%09%95%09%BE%09%98%09%BE%09%A4%09%C7%00+%09%86%09%B9%09%A4%00+%09%95%09%BE%09%A8%09%BF%09%9C%00+%09%AB%09%BE%09%A4%09%C7%09%AE%09%BE%00+%00(%09%E8%09%EB%00)%00+%09%9A%09%BF%09%95%09%BF%09%CE%09%B8%09%BE%09%A7%09%C0%09%A8%00+%09%85%09%AC%09%B8%09%CD%09%A5%09%BE%09%DF%00+%09%AE%09%BE%09%B0%09%BE%00+%09%97%09%C7%09%9B%09%C7%09%A8%00+%09d%00+%09%B6%09%C1%09%95%09%CD%09%B0%09%AC%09%BE%09%B0%00+%09%B0%09%BE%09%A4%00+%09%EF%09%9F%09%BE%09%DF%00+%00%40%00a%00d%00m%00i%00n'

print urllib.unquote(str1).decode('utf-16-be')
============Above code Python 2.7.5 and OUTPUT==============
Output:
রাজধানীর+কুড়িল+চৌরাস্তায়+ছুরিকাঘাতে+আহত+কানিজ+ফাতেমা+(২৫)+চিকিৎসাধীন+অবস্থায়+মারা+গেছেন+।+শুক্রবার+রাত+৯টায়[email protected]
==================================================

#!/usr/bin/python3
# -*- coding: UTF-8 -*-
import urllib3
import codecs
import locale
import sys
import unicodedata
from urllib.parse import unquote
from urllib.parse import unquote_plus
import urllib.parse

str1='%09%B0%09%BE%09%9C%09%A7%09%BE%09%A8%09%C0%09%B0%00+%09%95%09%C1%09%DC%09%BF%09%B2%00+%09%9A%09%CC%09%B0%09%BE%09%B8%09%CD%09%A4%09%BE%09%DF%00+%09%9B%09%C1%09%B0%09%BF%09%95%09%BE%09%98%09%BE%09%A4%09%C7%00+%09%86%09%B9%09%A4%00+%09%95%09%BE%09%A8%09%BF%09%9C%00+%09%AB%09%BE%09%A4%09%C7%09%AE%09%BE%00+%00(%09%E8%09%EB%00)%00+%09%9A%09%BF%09%95%09%BF%09%CE%09%B8%09%BE%09%A7%09%C0%09%A8%00+%09%85%09%AC%09%B8%09%CD%09%A5%09%BE%09%DF%00+%09%AE%09%BE%09%B0%09%BE%00+%09%97%09%C7%09%9B%09%C7%09%A8%00+%09d%00+%09%B6%09%C1%09%95%09%CD%09%B0%09%AC%09%BE%09%B0%00+%09%B0%09%BE%09%A4%00+%09%EF%09%9F%09%BE%09%DF%00+%00%40%00a%00d%00m%00i%00n'

strtobyte=bytes(unquote(str1),'utf-8').decode('utf-16-be')
print(strtobyte)
============Above code on Python 3.6.8 and OUTPUT==============
Output:
৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽+(৯뾽৯뾽)+৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽৯뾽৯뾽+।+৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽৯뾽[email protected]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Migration of Python2 and Python3 using Modernize and Future Rakshan 4 1,201 Feb-21-2022, 08:26 PM
Last Post: Gribouillis
  flask app decoding problem mesbah 0 1,466 Aug-01-2021, 08:32 PM
Last Post: mesbah
  Decoding a serial stream AKGentile1963 7 4,857 Mar-20-2021, 08:07 PM
Last Post: deanhystad
  python2 python3 messed up : How to fix ? hary 15 5,338 Dec-30-2020, 08:26 PM
Last Post: hary
  xml decoding failure(bs4) roughstroke 1 1,502 May-09-2020, 04:37 PM
Last Post: snippsat
  Getting a small Python2 prog to run in Python3 steve140 4 2,496 Apr-19-2020, 09:27 AM
Last Post: steve140
  output mismatching when porting a python from python2 env to python3 env prayuktibid 2 1,873 Jan-21-2020, 04:41 AM
Last Post: prayuktibid
  Gnuradio python3 is not compatible python3 xmlrpc library How Can I Fix İt ? muratoznnnn 3 3,841 Nov-07-2019, 05:47 PM
Last Post: DeaD_EyE
  utf-8 decoding failed every time i try adnanahsan 21 7,427 Aug-27-2019, 04:25 PM
Last Post: adnanahsan
  Trying to run a python2 script dagamer1991 3 1,791 Aug-12-2019, 12:33 PM
Last Post: buran

Forum Jump:

User Panel Messages

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