Après la mise à niveau vers Django 1.5, j'ai commencé à obtenir des erreurs comme celle-ci :
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 92, in get_response
response = middleware_method(request)
File "/usr/local/lib/python2.7/dist-packages/django/middleware/common.py", line 57, in process_request
host = request.get_host()
File "/usr/local/lib/python2.7/dist-packages/django/http/request.py", line 72, in get_host
"Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS): %s" % host)
SuspiciousOperation: Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS): www.google.com
<WSGIRequest
path:/,
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKIES:{},
META:{'CONTENT_LENGTH': '',
'CONTENT_TYPE': '',
'DOCUMENT_ROOT': '/etc/nginx/html',
'HTTP_ACCEPT': 'text/html',
'HTTP_HOST': 'www.google.com',
'HTTP_PROXY_CONNECTION': 'close',
'HTTP_USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',
'PATH_INFO': u'/',
'QUERY_STRING': '',
'REMOTE_ADDR': '210.245.91.104',
'REMOTE_PORT': '49347',
'REQUEST_METHOD': 'GET',
'REQUEST_URI': '/',
u'SCRIPT_NAME': u'',
'SERVER_NAME': 'www.derekkwok.net',
'SERVER_PORT': '80',
'SERVER_PROTOCOL': 'HTTP/1.0',
'uwsgi.node': 'derekkwok',
'uwsgi.version': '1.4.4',
'wsgi.errors': <open file 'wsgi_errors', mode 'w' at 0xb6d99c28>,
'wsgi.file_wrapper': <built-in function uwsgi_sendfile>,
'wsgi.input': <uwsgi._Input object at 0x953e698>,
'wsgi.multiprocess': True,
'wsgi.multithread': False,
'wsgi.run_once': False,
'wsgi.url_scheme': 'http',
'wsgi.version': (1, 0)}>
J'ai mis ALLOWED_HOSTS = ['.derekkwok.net']
dans mon fichier settings.py.
Qu'est-ce qui se passe ici ? Quelqu'un se fait-il passer pour Google et accède-t-il à mon site ? Ou s'agit-il d'un cas bénin où quelqu'un a mal défini son en-tête HTTP_HOST ?
0 votes
Avez-vous trouvé le moyen de résoudre ce problème ? Je suis confronté au même problème. J'enregistre une centaine de ces erreurs chaque jour. Aucune idée si c'est quelque chose dont je dois m'inquiéter.
3 votes
Cet article de blog propose une bonne façon d'arrêter les courriels : tiwoc.de/blog/2013/03/
2 votes
Réponses alternatives stackoverflow.com/a/25114003/1714030 , stackoverflow.com/a/21170400/1714030 , stackoverflow.com/q/15238506/1714030 y stackoverflow.com/q/18220519/1714030