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:
রাজধানীর+কুড়িল+চৌরাস্তায়+ছুরিকাঘাতে+আহত+কানিজ+ফাতেমা+(২৫)+চিকিৎসাধীন+অবস্থায়+মারা+গেছেন+।+শুক্রবার+রাত+৯টায়+@admin
==================================================

#!/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:
৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽+(৯뾽৯뾽)+৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽৯뾽৯뾽+।+৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽+৯뾽৯뾽৯뾽৯뾽+@admin
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Decoding lat/long in file name johnmcd 4 266 Mar-22-2024, 11:51 AM
Last Post: johnmcd
  Enigma Decoding Problem krisarmstrong 4 629 Dec-14-2023, 10:42 AM
Last Post: Larz60+
Sad Migrating of python2 script to python3 zuri 7 868 Oct-05-2023, 02:40 PM
Last Post: snippsat
  Migration of Python2 and Python3 using Modernize and Future Rakshan 5 2,454 Oct-05-2023, 08:55 AM
Last Post: zuri
  json decoding error deneme2 10 3,391 Mar-22-2023, 10:44 PM
Last Post: deanhystad
  flask app decoding problem mesbah 0 2,309 Aug-01-2021, 08:32 PM
Last Post: mesbah
  Decoding a serial stream AKGentile1963 7 8,338 Mar-20-2021, 08:07 PM
Last Post: deanhystad
  python2 python3 messed up : How to fix ? hary 15 7,837 Dec-30-2020, 08:26 PM
Last Post: hary
  xml decoding failure(bs4) roughstroke 1 2,210 May-09-2020, 04:37 PM
Last Post: snippsat
  Getting a small Python2 prog to run in Python3 steve140 4 3,796 Apr-19-2020, 09:27 AM
Last Post: steve140

Forum Jump:

User Panel Messages

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