-1

I am passing referrer URL from javascript to flask entry point function

but when I receive on the flask side it looks like this http%3A%2F%2F127.0.0.1%3A5000%2F

instead of http:\\127.0.0.1:5000 how can I fix this ? should I fix it on the client end or on the flask end?

Ciasto piekarz
  • 7,853
  • 18
  • 101
  • 197

1 Answers1

0

First of all - it`s just the URL with escaped special characters.

Python 3:

>>> from urllib.parse import unquote
>>> unquote('http%3A%2F%2F127.0.0.1%3A5000%2F')
'http://127.0.0.1:5000/'

Python 2:

>>> from urllib import unquote
>>> unquote('http%3A%2F%2F127.0.0.1%3A5000%2F')
'http://127.0.0.1:5000/'

So, I think, you should just unquote it when using it on Flask end.

Also, take in account that there are 2 versions of unquote - unquote() and unquote_plus(). As the manual says: unquote_plus() is like unquote(), but 'also replaces plus signs by spaces, as required for unquoting HTML form values.' https://docs.python.org/2.7/library/urllib.html#urllib.unquote

vchslv13
  • 73
  • 7