来自文档引荐来源网址的格式错误 URL
mallformated URL from document referrer
我正在将推荐人 URL 从 javascript 传递到 flask 入口点函数
但是当我收到烧瓶一侧时,它看起来像这样 http%3A%2F%2F127.0.0.1%3A5000%2F
而不是 http:\127.0.0.1:5000
我该如何解决这个问题?我应该在客户端还是在烧瓶端修复它?
首先 - 它只是带有转义特殊字符的 URL。
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/'
所以,我认为,你应该在 Flask 端使用它时取消引用它。
此外,请注意有 2 个版本的 unquote - unquote()
和 unquote_plus()
。正如手册所说:unquote_plus()
类似于 unquote()
,但 'also replaces plus signs by spaces, as required for unquoting HTML form values.'
https://docs.python.org/2.7/library/urllib.html#urllib.unquote
我正在将推荐人 URL 从 javascript 传递到 flask 入口点函数
但是当我收到烧瓶一侧时,它看起来像这样 http%3A%2F%2F127.0.0.1%3A5000%2F
而不是 http:\127.0.0.1:5000
我该如何解决这个问题?我应该在客户端还是在烧瓶端修复它?
首先 - 它只是带有转义特殊字符的 URL。
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/'
所以,我认为,你应该在 Flask 端使用它时取消引用它。
此外,请注意有 2 个版本的 unquote - unquote()
和 unquote_plus()
。正如手册所说:unquote_plus()
类似于 unquote()
,但 'also replaces plus signs by spaces, as required for unquoting HTML form values.'
https://docs.python.org/2.7/library/urllib.html#urllib.unquote