Do you host the site from the same server on which you are trying to check it? docs
Please note that when you use a single-threaded development server, checking the URL served by the same server will hang. This should not be a problem for multithreaded servers.
This is not like its form level fault tolerance
>>> from django import forms >>> f = forms.URLField() >>> f.clean('http://www.nacolmeia.com.br/do/Home/oferta/EnER') u'http://www.nacolmeia.com.br/do/Home/oferta/EnER' >>> f.clean('sadfas') Traceback (most recent call last): File "<console>", line 1, in <module> File "/home/dev/.virtualenvs/thepidb/lib/python2.7/site-packages/django/forms/fields.py", line 171, in clean self.run_validators(value) File "/home/dev/.virtualenvs/thepidb/lib/python2.7/site-packages/django/forms/fields.py", line 160, in run_validators raise ValidationError(errors) ValidationError: [u'Enter a valid URL.'] >>>
If you do not need to verify that the website does not return 404, in your models.py file
url = models.URLField(verify_exists=False)
change
after some digging in the django here
source code, and some were messing around with the shell, I'm still not sure why the URL with the headers causes a redirect loop.
>>> from django.core.validators import URLValidator >>> u = URLValidator(verify_exists=True) >>> u.__call__('http://www.nacolmeia.com.br/do/Home/oferta/EnER') Traceback (most recent call last): File "<console>", line 1, in <module> File "/home/dev/.virtualenvs/thepidb/lib/python2.7/site-packages/django/core/validators.py", line 105, in __call__ raise broken_error ValidationError: [u'This URL appears to be a broken link.'] >>> u.__call__('http://www.nacolmeia.com.br/do/home/oferta/ener') >>>
An exception to the exception is an HTTPError:
File "/usr/lib/python2.7/urllib2.py", line 606, in http_error_302 return self.parent.open(new, timeout=req.timeout) File "/usr/lib/python2.7/urllib2.py", line 398, in open response = meth(req, response) File "/usr/lib/python2.7/urllib2.py", line 511, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.7/urllib2.py", line 430, in error result = self._call_chain(*args) File "/usr/lib/python2.7/urllib2.py", line 370, in _call_chain result = func(*args) File "/usr/lib/python2.7/urllib2.py", line 606, in http_error_302 return self.parent.open(new, timeout=req.timeout) File "/usr/lib/python2.7/urllib2.py", line 398, in open response = meth(req, response) File "/usr/lib/python2.7/urllib2.py", line 511, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.7/urllib2.py", line 430, in error result = self._call_chain(*args) File "/usr/lib/python2.7/urllib2.py", line 370, in _call_chain result = func(*args) File "/usr/lib/python2.7/urllib2.py", line 596, in http_error_302 self.inf_msg + msg, headers, fp) HTTPError: HTTP Error 302: The HTTP server returned a redirect error that would lead to an infinite loop. The last 30x error message was: Found >>>
here are some posts talking about HTTPError: here
and here
it looks like it has something to do with cookies, but I cannot offer a good explanation, I will leave it to someone else.
A workaround that might work if you don't want to turn off validation but don't care about capitalizing your URLs is to override the clean_field method of your forms.
def clean_your_url_field(self): return self.cleaned_data['your_url_field'].lower()