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


Groups > comp.lang.python > #18330

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

From Roy Smith <roy@panix.com>
Newsgroups comp.lang.python
Subject Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error
Date 2012-01-02 10:47 -0500
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <roy-C5BA54.10470902012012@news.panix.com> (permalink)
References (3 earlier) <1f45fa2a-0c4f-4362-bc75-e73ce16595ab@o9g2000vbc.googlegroups.com> <144a4387-e80e-4782-a6eb-aecc1e742dc6@v14g2000yqh.googlegroups.com> <5c874675-ec98-445f-af91-9741413c512d@z1g2000vbx.googlegroups.com> <mailman.4313.1325513347.27778.python-list@python.org> <6b787f23-5813-4831-a349-02883f564da4@q7g2000yqn.googlegroups.com>

Show all headers | View raw


In article 
<6b787f23-5813-4831-a349-02883f564da4@q7g2000yqn.googlegroups.com>,
 ÉΪɫɻόλαος Κούρας <nikos.kouras@gmail.com> wrote:

> On 2 ÉßÉΩÉΥ, 16:00, Heiko Wundram <modeln...@modelnine.org> wrote:
> > 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.
> 
> 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?

try:
   host =  socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
except socket.herror:
   host = "<unknown host>"

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