python3 decoding problem but python2 OK - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: python3 decoding problem but python2 OK (/thread-22866.html) |
python3 decoding problem but python2 OK - mesbah - Nov-30-2019 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============== ==================================================#!/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==============
|