Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #18327

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

Date 2012-01-02 15:00 +0100
From Heiko Wundram <modelnine@modelnine.org>
Subject Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error
References (1 earlier) <mailman.3984.1324567957.27778.python-list@python.org> <920839e5-58fa-4fdf-9c88-7bed9a7448fd@d10g2000vbh.googlegroups.com> <1f45fa2a-0c4f-4362-bc75-e73ce16595ab@o9g2000vbc.googlegroups.com> <144a4387-e80e-4782-a6eb-aecc1e742dc6@v14g2000yqh.googlegroups.com> <5c874675-ec98-445f-af91-9741413c512d@z1g2000vbx.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.4313.1325513347.27778.python-list@python.org> (permalink)

Show all headers | View raw


Am 02.01.2012 14:25, schrieb Νικόλαος Κούρας:
> On 23 Δεκ 2011, 19:14, Νικόλαος Κούρας<nikos.kou...@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.

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.

-- 
--- Heiko.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-02 05:25 -0800
  Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Heiko Wundram <modelnine@modelnine.org> - 2012-01-02 15:00 +0100
    Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-02 07:29 -0800
      Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Roy Smith <roy@panix.com> - 2012-01-02 10:47 -0500
        Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-02 10:17 -0800

csiph-web