Reputation: 21
I´m trying to get a param from a URL using the urlparse function, but when i tried to decode the param the string changes and gives me an error. like this:
url = request.url
parsed = urlparse.urlparse(url)
log.info(parsed)
url_code = urlparse.parse_qs(parsed.query)['id_compra']
log.info(url_code)
the output looks like this
INFO http://c34f30683db9.ngrok.io/payment?id_compra=%2FYkv86B1UdMds9CuYr%2FbMCD3BpKL%2FzElNtVRc8KiALXWgtB343EjrUsmTObrBzv48FshzRu%2FD3Www4B+5SAxcb2xx78=
INFO ParseResult(scheme='http', netloc='c34f30683db9.ngrok.io', path='/payment', params='', query='id_compra=%2FYkv86B1UdMds9CuYr%2FbMCD3BpKL%2FzElNtVRc8KiALXWgtB343EjrUsmTObrBzv48FshzRu%2FD3Www4B+5SAxcb2xx78=', fragment='')
INFO ['/Ykv86B1UdMds9CuYr/bMCD3BpKL/zElNtVRc8KiALXWgtB343EjrUsmTObrBzv48FshzRu/D3Www4B 5SAxcb2xx78=']
I want to obtain the param like it is in the URL, but the result changes the character '+' to an empty space and I don't want that to happen.
Upvotes: 0
Views: 177
Reputation: 252
you can probably quote the query to get back to the urlsafe format. urlparse some some simple unquoting of the query and you just need to reverese that process.
from urllib.parse import quote
urlsafequery = quote(urlquery)
Upvotes: 0