socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error

Νικόλαος Κούρας nikos.kouras at gmail.com
Mon Jan 2 10:29:10 EST 2012


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'] )[0] 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 81.14.209.35 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?




More information about the Python-list mailing list