Στις 12/7/2013 2:47 μμ, ο/η Wayne Werner έγραψε:
On Thu, 4 Jul 2013, Νίκος Γκρ33κ wrote:

Στις 4/7/2013 6:10 μμ, ο/η MRAB έγραψε:
What do you mean "I don't know how to catch the exception with
OSError"? You've tried "except socket.gaierror" and "except
socket.herror", well just write "except OSError" instead!


try:
    host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
except OSError:
    host = "UnResolved"

produces also an internal server error.

Are you sure is just except OSError ?


Have you ensured that 'REMOTE_ADDR' is actually a key in os.environ? I
highly recommend using the logging module to help diagnose what the
actual exception is.

HTH,
-W

Yes it is a key, but the problem as i suspected was cloudflare.
i had to use os.environ['HTTP_CF_CONNECTING_IP'] that cloudflare passes as variable i the cgi enviroment in order to retrieve the visitor's ip.


try:
        gi = pygeoip.GeoIP('/usr/local/share/GeoLiteCity.dat')
        city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] )
        host = socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0]
except Exception as e:
        host = repr(e)


Sometimes though iam still receiving the usual
UnicodeDecodeError('utf-8', b'\xc1\xf0\xef\xf4\xf5

but only for a few ip addresses, in moste cases it works.
--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to