django URLValidator produced bogus errors

对着背影说爱祢 提交于 2019-12-04 02:39:43

Look at the source for URLValidator; if you specify check_exists, it makes a HEAD request to the URL to check if it's valid:

req = urllib2.Request(url, None, headers)
req.get_method = lambda: 'HEAD'
...
opener.open(req, timeout=10)

Try making the HEAD request to Amazon yourself, and you'll see the problem:

carl@chaffinch:~$ HEAD http://www.amazon.com
405 MethodNotAllowed
Date: Mon, 13 Aug 2012 18:50:56 GMT
Server: Server
Vary: Accept-Encoding,User-Agent
Allow: POST, GET
...

I can't see a way of solving this other than monkey-patching or otherwise extending URLValidator to use a GET or POST request; before doing so, you should think carefully about whether to use check_exists at all (without which this problem should go away). As core/validators.py itself says,

"The URLField verify_exists argument has intractable security and performance issues. Accordingly, it has been deprecated."

You'll find that the in-development version of Django has indeed disposed of this feature completely.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!