The data is UTF-8 encoded bytes escaped with URL quoting, so you want to decode, with urllib.parse.unquote(), which handles decoding from percent-encoded data to UTF-8 bytes and then to text, transparently:
from urllib.parse import unquote
url = unquote(url)
Demo:
>>> from urllib.parse import unquote
>>> url = 'example.com?title=%D0%BF%D1%80%D0%B0%D0%B2%D0%BE%D0%B2%D0%B0%D1%8F+%D0%B7%D0%B0%D1%89%D0%B8%D1%82%D0%B0'
>>> unquote(url)
'example.com?title=правовая+защита'
The Python 2 equivalent is urllib.unquote(), but this returns a bytestring, so you'd have to decode manually:
from urllib import unquote
url = unquote(url).decode('utf8')
Answer from Martijn Pieters on Stack OverflowPython
docs.python.org › 3 › library › urllib.parse.html
urllib.parse — Parse URLs into components
To support easier conversion of result objects between str and bytes, all return values from URL parsing functions provide either an encode() method (when the result contains str data) or a decode() method (when the result contains bytes data). The signatures of these methods match those of the corresponding str and bytes methods (except that the default encoding is 'ascii' rather than 'utf-8').
Top answer 1 of 5
696
The data is UTF-8 encoded bytes escaped with URL quoting, so you want to decode, with urllib.parse.unquote(), which handles decoding from percent-encoded data to UTF-8 bytes and then to text, transparently:
from urllib.parse import unquote
url = unquote(url)
Demo:
>>> from urllib.parse import unquote
>>> url = 'example.com?title=%D0%BF%D1%80%D0%B0%D0%B2%D0%BE%D0%B2%D0%B0%D1%8F+%D0%B7%D0%B0%D1%89%D0%B8%D1%82%D0%B0'
>>> unquote(url)
'example.com?title=правовая+защита'
The Python 2 equivalent is urllib.unquote(), but this returns a bytestring, so you'd have to decode manually:
from urllib import unquote
url = unquote(url).decode('utf8')
2 of 5
181
If you are using Python 3, you can use urllib.parse.unquote:
url = """example.com?title=%D0%BF%D1%80%D0%B0%D0%B2%D0%BE%D0%B2%D0%B0%D1%8F+%D0%B7%D0%B0%D1%89%D0%B8%D1%82%D0%B0"""
import urllib.parse
urllib.parse.unquote(url)
gives:
'example.com?title=правовая+защита'
Videos
URLDecoder
urldecoder.io › python
URL Decoding query strings or form parameters in Python | URLDecoder
In Python 3+, You can URL decode any string using the unquote() function provided by urllib.parse package.
PyPI
pypi.org › project › URLDecoder
URLDecoder
March 17, 2023 - JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.sql › api › pyspark.sql.functions.url_decode.html
pyspark.sql.functions.url_decode — PySpark 4.1.1 documentation
URL function: Decodes a URL-encoded string in ‘application/x-www-form-urlencoded’ format to its original format.
DEV Community
dev.to › k4ml › python-urldecode-on-command-line-2ek9
Python urldecode on command line - DEV Community
December 2, 2018 - alias urldecode='python3 -c "import sys, urllib.parse as ul;print(ul.unquote_plus(sys.argv[1]))"' Then you can use it as:- urldecode '"status":"SUCCESS"' "status":"SUCCESS" Now that's perfect. But the data that I want to decode must be passed through unix pipe, like this:- grep 'status: 504' /var/log/local0* | awk '{ print $10}' | xargs urldecode ·
Urldecoder
urldecoder.net › python-urldecode
Python unqoute() - URL Decode
>>> import urllib >>> url = u'http://example.com/?param=url decode' >>> urllib.unquote( url ).decode( 'utf8' ) >>> print urllib.unquote( url ).decode( 'utf8' ) http://example.com/?param=url encode · github.com/urldecoder/examples/blob/main/unquote.py · Python urlencode ·
URL Encoder
urlencoder.io › python
How to encode URLs in Python | URLEncoder
URL Encode online. URLEncoder is a simple and easy to use online tool to convert any string to URL Encoded format in real time. It also contains several articles on how to URL Encode a query string or form parameter in different programming languages.
Python-Fiddle
python-fiddle.com › tools › urldecoder
Online URL Decoder
URL decoding is the process of converting an encoded URL back to its original form by replacing the percent-encoded characters with their corresponding special characters.
URL Decode
urldecoder.org
URL Decode and Encode - Online
Decode from URL-encoded format or encode into it with various advanced options. Our site has an easy to use online tool to convert your data.