Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #18330
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!novia!news-out.readnews.com!news-xxxfer.readnews.com!panix!roy |
|---|---|
| From | Roy Smith <roy@panix.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error |
| Date | Mon, 02 Jan 2012 10:47:09 -0500 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Lines | 33 |
| Message-ID | <roy-C5BA54.10470902012012@news.panix.com> (permalink) |
| References | <d3865134-491c-45ea-a033-a394e64701db@z19g2000vbe.googlegroups.com> <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> <mailman.4313.1325513347.27778.python-list@python.org> <6b787f23-5813-4831-a349-02883f564da4@q7g2000yqn.googlegroups.com> |
| NNTP-Posting-Host | localhost |
| X-Trace | reader1.panix.com 1325519230 21610 127.0.0.1 (2 Jan 2012 15:47:10 GMT) |
| X-Complaints-To | abuse@panix.com |
| NNTP-Posting-Date | Mon, 2 Jan 2012 15:47:10 +0000 (UTC) |
| User-Agent | MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:18330 |
Show key headers only | 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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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