Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!txtfeed1.tudelft.nl!tudelft.nl!txtfeed2.tudelft.nl!amsnews11.chello.com!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.040 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'hosts': 0.09; 'subject:error': 0.09; '(1,': 0.16; 'lookup': 0.16; 'name)': 0.16; 'posting,': 0.16; 'received:10.2': 0.16; 'retrieving': 0.16; 'wrote:': 0.18; 'help.': 0.19; 'trying': 0.21; '(i.e.,': 0.21; 'appropriate': 0.22; '(or': 0.22; "doesn't": 0.22; 'header:In- Reply-To:1': 0.22; 'all:': 0.23; 'assigning': 0.23; 'correctly.': 0.24; 'says': 0.25; "i'm": 0.26; 'error': 0.29; 'host': 0.30; 'conditional': 0.30; 'fails.': 0.30; 'throwing': 0.30; '---': 0.31; 'header:User-Agent:1': 0.33; 'to:addr:python-list': 0.34; 'skip:\xce 10': 0.38; 'received:org': 0.38; 'some': 0.38; 'skip:o 20': 0.38; 'why': 0.39; 'to:addr:python.org': 0.40; '8bit%:92': 0.61; 'internet': 0.64; 'due': 0.66; 'webpage': 0.67; '8bit%:100': 0.69; 'reverse': 0.73; 'resolution,': 0.84; 'subject:( ': 0.84; 'subject:skip:s 20': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=modelnine.org; s=modelnine1012; t=1325512828; bh=DtO7kl4aGgMapr/MJf0VRXjIIknqi63BBKAB/LOpNkM=; h=Message-ID:Date:From:MIME-Version:To:Subject:References: In-Reply-To:Content-Type:Content-Transfer-Encoding; b=HHOSaI4pfhOJitlMocfF1Z4Src25GcHV3Dx/O95aYhmbMvf0GsJuzj/K4UVNWYL62 99g5CUOrE90prA033oCT3+h82EbQfVvcLAMShNOuWrb1gFCWhF0bJ0m3f8N3+ElLbx haUDbRTh+m7W3IoJUtHYzs52pwgQX29OMk1F15UE= Date: Mon, 02 Jan 2012 15:00:26 +0100 From: Heiko Wundram User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0) Gecko/20111222 Thunderbird/10.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error References: <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> In-Reply-To: <5c874675-ec98-445f-af91-9741413c512d@z1g2000vbx.googlegroups.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1325513347 news.xs4all.nl 6962 [2001:888:2000:d::a6]:51025 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18327 Am 02.01.2012 14:25, schrieb Νικόλαος Κούρας: > On 23 Δεκ 2011, 19:14, Νικόλαος Κούρας 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 .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.