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


Groups > comp.lang.python > #17736 > unrolled thread

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

Started byΝικόλαος Κούρας <nikos.kouras@gmail.com>
First post2011-12-22 06:40 -0800
Last post2012-01-02 11:54 -0800
Articles 20 on this page of 25 — 9 participants

Back to article view | Back to comp.lang.python


Contents

  socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2011-12-22 06:40 -0800
    Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Rami Chowdhury <rami.chowdhury@gmail.com> - 2011-12-22 15:32 +0000
      Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2011-12-22 08:29 -0800
        Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error becky_lewis <bex.lewis@gmail.com> - 2011-12-23 02:41 -0800
          Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2011-12-23 09:14 -0800
            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
    Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error becky_lewis <bex.lewis@gmail.com> - 2011-12-22 07:52 -0800
    Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-01-02 16:49 +0100
      Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-02 10:18 -0800
        Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Roy Smith <roy@panix.com> - 2012-01-02 13:42 -0500
          Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-02 11:51 -0800
            Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Roy Smith <roy@panix.com> - 2012-01-02 15:31 -0500
              Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-09 14:19 -0800
                Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Dominic Binks <dbinks@codeaurora.org> - 2012-01-09 14:35 -0800
                  Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-09 15:04 -0800
                  Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-01-10 07:42 +0100
                    Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Chris Angelico <rosuav@gmail.com> - 2012-01-10 18:29 +1100
                Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Chris Angelico <rosuav@gmail.com> - 2012-01-10 10:14 +1100
                Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Nick Dokos <nicholas.dokos@hp.com> - 2012-01-09 18:32 -0500
                Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Chris Angelico <rosuav@gmail.com> - 2012-01-10 13:08 +1100
          Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-02 11:54 -0800

Page 1 of 2  [1] 2  Next page →


#17736 — socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error

FromΝικόλαος Κούρας <nikos.kouras@gmail.com>
Date2011-12-22 06:40 -0800
Subjectsocket.gethostbyaddr( os.environ['REMOTE_ADDR'] error
Message-ID<d3865134-491c-45ea-a033-a394e64701db@z19g2000vbe.googlegroups.com>
Hello when i try to visit my webpage i get the error it displays. Iam
not posting it since you can see it by visiting my webpage at
http://superhost.gr

Please if you can tell me what might be wrong.

[toc] | [next] | [standalone]


#17739

FromRami Chowdhury <rami.chowdhury@gmail.com>
Date2011-12-22 15:32 +0000
Message-ID<mailman.3984.1324567957.27778.python-list@python.org>
In reply to#17736
2011/12/22 Νικόλαος Κούρας <nikos.kouras@gmail.com>:
> Hello when i try to visit my webpage i get the error it displays. Iam
> not posting it since you can see it by visiting my webpage at
> http://superhost.gr
>
> Please if you can tell me what might be wrong.

I can't see any errors on that page -- can you please post the
complete traceback so we can all see it?

-- 
Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
+44-7581-430-517 / +1-408-597-7068 / +88-0189-245544

[toc] | [prev] | [next] | [standalone]


#17741

FromΝικόλαος Κούρας <nikos.kouras@gmail.com>
Date2011-12-22 08:29 -0800
Message-ID<920839e5-58fa-4fdf-9c88-7bed9a7448fd@d10g2000vbh.googlegroups.com>
In reply to#17739
On 22 Δεκ, 17:32, Rami Chowdhury <rami.chowdh...@gmail.com> wrote:
> 2011/12/22 Νικόλαος Κούρας <nikos.kou...@gmail.com>:
>
> > Hello when i try to visit my webpage i get the error it displays. Iam
> > not posting it since you can see it by visiting my webpage at
> >http://superhost.gr
>
> > Please if you can tell me what might be wrong.
>
> I can't see any errors on that page -- can you please post the
> complete traceback so we can all see it?

Yes of course. Its the following:

A problem occurred in a Python script. Here is the sequence of
function calls leading up to the error, in the order they occurred.

 /home/nikos/public_html/cgi-bin/counter.py
   15
   16 hits = 0
   17 host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
   18 date = datetime.datetime.now().strftime( '%y-%m-%d %H:%M:%S' )
   19 agent = os.environ['HTTP_USER_AGENT']
host undefined, socket = <module 'socket' from '/usr/lib64/python2.4/
socket.pyc'>, socket.gethostbyaddr = <built-in function
gethostbyaddr>, os = <module 'os' from '/usr/lib64/python2.4/os.pyc'>,
os.environ = {'REDIRECT_QUERY_STRING': 'page=index.html',
'HT...e,sdch', 'UNIQUE_ID': 'TvNasbAJGaoAABtUy@gAAAAI'}
herror: (1, '\xb6\xe3\xed\xf9\xf3\xf4\xef \xfc\xed\xef\xec\xe1
\xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2')
      args = (1, '\xb6\xe3\xed\xf9\xf3\xf4\xef \xfc\xed\xef\xec\xe1
\xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2')

[toc] | [prev] | [next] | [standalone]


#17804

Frombecky_lewis <bex.lewis@gmail.com>
Date2011-12-23 02:41 -0800
Message-ID<1f45fa2a-0c4f-4362-bc75-e73ce16595ab@o9g2000vbc.googlegroups.com>
In reply to#17741
Is there any possibility that you can tell us what the script actually
is or provide a code listing (use pastebin if it's big)?

[toc] | [prev] | [next] | [standalone]


#17818

FromΝικόλαος Κούρας <nikos.kouras@gmail.com>
Date2011-12-23 09:14 -0800
Message-ID<144a4387-e80e-4782-a6eb-aecc1e742dc6@v14g2000yqh.googlegroups.com>
In reply to#17804
On 23 Δεκ, 12:41, becky_lewis <bex.le...@gmail.com> wrote:
> Is there any possibility that you can tell us what the script actually
> is or provide a code listing (use pastebin if it's big)?

The script is about retrieving and storing the visitros hostnames to
mysql database creating a log file.

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.

What do you understand from the traceback?!

[toc] | [prev] | [next] | [standalone]


#18326

FromΝικόλαος Κούρας <nikos.kouras@gmail.com>
Date2012-01-02 05:25 -0800
Message-ID<5c874675-ec98-445f-af91-9741413c512d@z1g2000vbx.googlegroups.com>
In reply to#17818
On 23 Δεκ 2011, 19:14, Νικόλαος Κούρας <nikos.kou...@gmail.com> wrote:
> On 23 Äåê, 12:41, becky_lewis <bex.le...@gmail.com> wrote:
>
> > Is there any possibility that you can tell us what the script actually
> > is or provide a code listing (use pastebin if it's big)?
>
> The script is about retrieving and storing the visitros hostnames to
> mysql database creating a log file.
>
> 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.
>
> What do you understand from the traceback?!

Please i need some help. My webpage doesn't work due to this error...

[toc] | [prev] | [next] | [standalone]


#18327

FromHeiko Wundram <modelnine@modelnine.org>
Date2012-01-02 15:00 +0100
Message-ID<mailman.4313.1325513347.27778.python-list@python.org>
In reply to#18326
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.

[toc] | [prev] | [next] | [standalone]


#18329

FromΝικόλαος Κούρας <nikos.kouras@gmail.com>
Date2012-01-02 07:29 -0800
Message-ID<6b787f23-5813-4831-a349-02883f564da4@q7g2000yqn.googlegroups.com>
In reply to#18327
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?

[toc] | [prev] | [next] | [standalone]


#18330

FromRoy Smith <roy@panix.com>
Date2012-01-02 10:47 -0500
Message-ID<roy-C5BA54.10470902012012@news.panix.com>
In reply to#18329
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>"

[toc] | [prev] | [next] | [standalone]


#18338

FromΝικόλαος Κούρας <nikos.kouras@gmail.com>
Date2012-01-02 10:17 -0800
Message-ID<7a9e8fce-3a6a-4b16-b8f0-411106a1d1e3@e2g2000vbb.googlegroups.com>
In reply to#18330
On 2 Ιαν, 17:47, Roy Smith <r...@panix.com> wrote:
> In article
> <6b787f23-5813-4831-a349-02883f564...@q7g2000yqn.googlegroups.com>,
>  ÉΪɫɻόλαος Κούρας <nikos.kou...@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>"

Thank you very much.

[toc] | [prev] | [next] | [standalone]


#17740

Frombecky_lewis <bex.lewis@gmail.com>
Date2011-12-22 07:52 -0800
Message-ID<21f682a5-fc62-4820-9cc5-f5dfd064ec6a@t16g2000vba.googlegroups.com>
In reply to#17736
On Dec 22, 2:40 pm, Νικόλαος Κούρας <nikos.kou...@gmail.com> wrote:
> Hello when i try to visit my webpage i get the error it displays. Iam
> not posting it since you can see it by visiting my webpage athttp://superhost.gr
>
> Please if you can tell me what might be wrong.

It doesn't seem entirely clear but if I had to guess I'd think that
for some reason os.environ['REMOTE_ADDR'] is not returning a good
value (os.environ is a dictionary holding all of the os evironment
variables).
According to the socket docs, this error gets raised for address
related errors.

[toc] | [prev] | [next] | [standalone]


#18331

FromThomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>
Date2012-01-02 16:49 +0100
Message-ID<jdsjld$mau$1@r03.glglgl.gl>
In reply to#17736
Am 22.12.2011 15:40 schrieb Νικόλαος Κούρας:
> Hello when i try to visit my webpage i get the error it displays. Iam
> not posting it since you can see it by visiting my webpage at
> http://superhost.gr
>
> Please if you can tell me what might be wrong.

What is wrong on this site? Mainly the unwanted sound.

Are you trying to sell something? Then you should try not to scare your 
potential customers away.

[toc] | [prev] | [next] | [standalone]


#18337

FromΝικόλαος Κούρας <nikos.kouras@gmail.com>
Date2012-01-02 10:18 -0800
Message-ID<bacea15d-fae0-4b1f-8a8e-a8b06b561fc0@t30g2000vbx.googlegroups.com>
In reply to#18331
On 2 Ιαν, 17:49, Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-
a470-7603bd3aa...@spamschutz.glglgl.de> wrote:
> Am 22.12.2011 15:40 schrieb Νικόλαος Κούρας:
>
> > Hello when i try to visit my webpage i get the error it displays. Iam
> > not posting it since you can see it by visiting my webpage at
> >http://superhost.gr
>
> > Please if you can tell me what might be wrong.
>
> What is wrong on this site? Mainly the unwanted sound.
>
> Are you trying to sell something? Then you should try not to scare your
> potential customers away.

I'am trying to present myself through my webpage as computer tech.
Is the background music so bad?! :-)

[toc] | [prev] | [next] | [standalone]


#18339

FromRoy Smith <roy@panix.com>
Date2012-01-02 13:42 -0500
Message-ID<roy-F4BA5C.13424802012012@news.panix.com>
In reply to#18337
In article 
<bacea15d-fae0-4b1f-8a8e-a8b06b561fc0@t30g2000vbx.googlegroups.com>,
 ÉΪɫɻόλαος Κούρας <nikos.kouras@gmail.com> wrote:

> I'am trying to present myself through my webpage as computer tech.
> Is the background music so bad?! :-)

Yes.  Background music on web sites is evil.

[toc] | [prev] | [next] | [standalone]


#18345

FromΝικόλαος Κούρας <nikos.kouras@gmail.com>
Date2012-01-02 11:51 -0800
Message-ID<24123dfe-b2fc-4f4c-8dfe-23bfef19b205@m10g2000vbc.googlegroups.com>
In reply to#18339
On 2 Ιαν, 20:42, Roy Smith <r...@panix.com> wrote:
> In article
> <bacea15d-fae0-4b1f-8a8e-a8b06b561...@t30g2000vbx.googlegroups.com>,
>  ÉΪɫɻόλαος Κούρας <nikos.kou...@gmail.com> wrote:
>
> > I'am trying to present myself through my webpage as computer tech.
> > Is the background music so bad?! :-)
>
> Yes.  Background music on web sites is evil.

Evil?!?! How come? :)

[toc] | [prev] | [next] | [standalone]


#18347

FromRoy Smith <roy@panix.com>
Date2012-01-02 15:31 -0500
Message-ID<roy-4CE54B.15314102012012@news.panix.com>
In reply to#18345
In article 
<24123dfe-b2fc-4f4c-8dfe-23bfef19b205@m10g2000vbc.googlegroups.com>,
 ÉΪɫɻόλαος Κούρας <nikos.kouras@gmail.com> wrote:

> On 2 ÉßÉΩÉΥ, 20:42, Roy Smith <r...@panix.com> wrote:
> > In article
> > <bacea15d-fae0-4b1f-8a8e-a8b06b561...@t30g2000vbx.googlegroups.com>,
> > †ÉΪɫɻόλαος Κούρας <nikos.kou...@gmail.com> wrote:
> >
> > > I'am trying to present myself through my webpage as computer tech.
> > > Is the background music so bad?! :-)
> >
> > Yes.  Background music on web sites is evil.
> 
> Evil?!?! How come? :)

Because people hate going to web sites and having background music start 
to play.  But, there are better fora than here for discussions of web 
site best practices.

[toc] | [prev] | [next] | [standalone]


#18712

FromΝικόλαος Κούρας <nikos.kouras@gmail.com>
Date2012-01-09 14:19 -0800
Message-ID<f683b8f4-3a59-4c9f-94ef-82a9017dcd31@m20g2000vbf.googlegroups.com>
In reply to#18347
Can you please explain me what the [0] in host =
socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] does at the end?

Why not just host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )
instead? what is the need of [0] ?

[toc] | [prev] | [next] | [standalone]


#18713

FromDominic Binks <dbinks@codeaurora.org>
Date2012-01-09 14:35 -0800
Message-ID<mailman.4552.1326148616.27778.python-list@python.org>
In reply to#18712
On 1/9/2012 2:19 PM, Νικόλαος Κούρας wrote:
> Can you please explain me what the [0] in host =
> socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] does at the end?
>
> Why not just host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )
> instead? what is the need of [0] ?

The address database can have multiple names for the same IP address so 
gethostbyaddr returns a list - [0] being the first item in the list (and 
usually considered the canonical name)

-- 
Dominic Binks: dbinks@codeaurora.org
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum

[toc] | [prev] | [next] | [standalone]


#18714

FromΝικόλαος Κούρας <nikos.kouras@gmail.com>
Date2012-01-09 15:04 -0800
Message-ID<1e0e10e9-263f-4fde-8cdd-ece561c2c5fd@w4g2000vbc.googlegroups.com>
In reply to#18713
On 10 Ιαν, 00:35, Dominic Binks <dbi...@codeaurora.org> wrote:
> On 1/9/2012 2:19 PM, Νικόλαος Κούρας wrote:
>
> > Can you please explain me what the [0] in host =
> > socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] does at the end?
>
> > Why not just host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )
> > instead? what is the need of [0] ?
>
> The address database can have multiple names for the same IP address so
> gethostbyaddr returns a list - [0] being the first item in the list (and
> usually considered the canonical name)

Thank you!

[toc] | [prev] | [next] | [standalone]


#18738

FromThomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>
Date2012-01-10 07:42 +0100
Message-ID<jegmkb$bl8$1@r03.glglgl.gl>
In reply to#18713
Am 09.01.2012 23:35 schrieb Dominic Binks:
> On 1/9/2012 2:19 PM, Νικόλαος Κούρας wrote:
>> Can you please explain me what the [0] in host =
>> socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] does at the end?
>>
>> Why not just host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )
>> instead? what is the need of [0] ?
>
> The address database can have multiple names for the same IP address so
> gethostbyaddr returns a list - [0] being the first item in the list (and
> usually considered the canonical name)

It might be noteworthy that it is nowadays preferrable to use 
getaddrinfo() instead. This way, you get all acceptable IP addresses, 
not only IPv4 ones. And then, you should not only try this one entry - 
[0] -, but iterate over all of them until you have a connection.

BTW: This behaviour might be useful with gethostbyaddr() as well - if 
the first one returned has gone away, you have the chance to reach the 
2nd one...


Thomas

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.python


csiph-web