socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error
roy at panix.com
Mon Jan 2 10:47:09 EST 2012
<6b787f23-5813-4831-a349-02883f564da4 at q7g2000yqn.googlegroups.com>,
ÃÎªÃÂ«ÃÂ»ÏÎ»Î±Î¿Ï ÎÎ¿ÏÏÎ±Ï <nikos.kouras at gmail.com> wrote:
> On 2 ÃÃÃÎ©ÃÎ¥, 16:00, Heiko Wundram <modeln... at modelnine.org> wrote:
> > Am 02.01.2012 14:25, schrieb ÃÎªÃÂ«ÃÂ»ÏÎ»Î±Î¿Ï ÎÎ¿ÏÏÎ±Ï:
> > > On 23 ÎÎµÎº 2011, 19:14, ÎÎ¹ÎºÏÎ»Î±Î¿Ï ÎÎ¿ÏÏÎ±Ï<nikos.kou... at gmail.com> Â wrote:
> > >> I dont know why this line host =
> > >> socket.gethostbyaddr( os.environ['REMOTE_ADDR'] ) fails sometimes
> > >> and some other times works ok retrieving the hostnames correctly.
> > > Please i need some help. My webpage doesn't work due to this error...
> > The error "herror: (1, ...)" says it all: the DNS-name (i.e., the
> > <something>.in-addr.arpa name) you're trying to resolve is unknown. Not
> > all hosts (or rather, IPs) on the internet have reverse lookups: try the
> > IP 126.96.36.199 from which I'm posting, and dig/nslookup will tell you
> > that it has no reverse resolution, which would result in gethostbyaddr()
> > throwing an herror-instance.
> I see
> > Basically: make the reverse lookup conditional by wrapping it in a
> > try:/except herror: and assigning an appropriate default for host in
> > case reverse lookup fails.
> Can tou show me how to write this please?
host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )
host = "<unknown host>"
More information about the Python-list