Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'charset:iso-8859-7': 0.04; 'expressions': 0.07; 'failing': 0.07; 'socket': 0.07; 'variables': 0.07; 'string': 0.09; 'properly.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'used.': 0.09; 'runs': 0.10; 'python': 0.11; '3.3,': 0.16; 'exist.': 0.16; 'illustrating': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:exception': 0.16; 'subject:expression': 0.16; '(you': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'server,': 0.19; '>>>': 0.22; 'import': 0.22; 'shell': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'header:X-Complaints-To:1': 0.27; 'installed': 0.27; "i'm": 0.30; 'code': 0.31; '"",': 0.31; 'file': 0.32; '(most': 0.33; 'basic': 0.35; 'display': 0.35; 'problem.': 0.35; 'skip:s 30': 0.35; 'prepare': 0.35; 'but': 0.35; 'representing': 0.36; 'should': 0.36; 'so,': 0.37; 'skip:o 20': 0.38; 'server': 0.38; 'question,': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'skip:o 30': 0.61; 'name': 0.63; 'dont': 0.67; 'default': 0.69; 'lack': 0.78; 'greek': 0.84; 'lien': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: Handling 3 operands in an expression without raising an exception Date: Thu, 26 Sep 2013 11:24:57 +0000 (UTC) References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-7 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 174.32.174.35 User-Agent: XPN/1.2.6 (Street Spirit ; Linux) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380194717 news.xs4all.nl 15895 [2001:888:2000:d::a6]:46666 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54812 On 26/9/2013 06:51, Νίκος wrote: >>>>> socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or >> os.environ.get('REMOTE_ADDR') or "Άγνωστη Προέλευση" )[0] >> Traceback (most recent call last): >> File "", line 1, in >> socket.gaierror: [Errno -2] Name or service not known >> >> You are just illustrating your lack of basic understaning. > > I'm surepirsed, becaus eon my domain [superhost.gr] the same lien of > code works withnout an error and it display the 'host' fileds properly. > > Perhaps its failing via shell or you do not have a web server installed > to prepare the enviromental variables or i dont know what else to hink. > > But in my website this code runs at the probelm with no problem. > In Python 3.3, but not on a web server, I get: >>> import socket >>> socket.gethostbyaddr("unknown")[0] Traceback (most recent call last): File "", line 1, in socket.gaierror: [Errno -2] Name or service not known >>> Question, do you get the same result on your server? (You can put the Greek string in place of "unknown" of course) If so, then the default value makes no sense; it'll cause an exception if it's ever used. If you insist on sticking to expressions (no try/catch, no if statements), then perhaps you should default to a string representing a domain which will always exist. -- DaveA