Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'mrab': 0.05; 'debug': 0.07; "subject:' ": 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:position': 0.09; 'try:': 0.09; 'works.': 0.09; 'advice,': 0.16; 'ensured': 0.16; 'oserror': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject: \n ': 0.16; 'subject:start': 0.16; 'wayne': 0.16; 'exception': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'module': 0.19; 'skip:p 40': 0.19; 'thu,': 0.19; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'passes': 0.24; 'logging': 0.26; 'post': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply- To:1': 0.27; 'tried': 0.27; 'host': 0.29; 'am,': 0.29; 'code': 0.31; "skip:' 10": 0.31; '>>>>': 0.31; 'cgi': 0.31; 'produces': 0.31; 'cases': 0.33; 'actual': 0.34; 'problem': 0.35; 'except': 0.35; 'skip:u 20': 0.35; 'usual': 0.35; 'but': 0.35; 'addresses,': 0.36; 'error.': 0.37; 'skip:o 20': 0.38; 'sometimes': 0.38; 'server': 0.38; 'to:addr:python-list': 0.38; 'subject:can': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'read': 0.60; 'catch': 0.60; 'is.': 0.60; 'problems.': 0.60; 'skip:o 30': 0.61; "you've": 0.63; 'city': 0.66; 'here': 0.66; 'yes': 0.68; '8bit%:92': 0.71; 'jul': 0.74; '2013,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Date: Fri, 12 Jul 2013 11:46:35 -0400 References: <51D57ADB.3050202@superhost.gr> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 174.32.174.30 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130623 Thunderbird/17.0.7 In-Reply-To: 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: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1373644014 news.xs4all.nl 16008 [2001:888:2000:d::a6]:43724 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50535 On 07/12/2013 07:56 AM, Ferrous Cranus wrote: > Στις 12/7/2013 2:47 μμ, ο/η Wayne Werner έγραψε: >> On Thu, 4 Jul 2013, Νίκος Γκρ33κ wrote: >> >>> Στις 4/7/2013 6:10 μμ, ο/η MRAB έγραψε: >>>> What do you mean "I don't know how to catch the exception with >>>> OSError"? You've tried "except socket.gaierror" and "except >>>> socket.herror", well just write "except OSError" instead! >>> >>> >>> try: >>> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] >>> except OSError: >>> host = "UnResolved" >>> >>> produces also an internal server error. >>> >>> Are you sure is just except OSError ? >>> >> >> Have you ensured that 'REMOTE_ADDR' is actually a key in os.environ? I >> highly recommend using the logging module to help diagnose what the >> actual exception is. >> >> HTH, >> -W > > Yes it is a key, but the problem as i suspected was cloudflare. > i had to use os.environ['HTTP_CF_CONNECTING_IP'] that cloudflare passes > as variable i the cgi enviroment in order to retrieve the visitor's ip. > > > try: > gi = pygeoip.GeoIP('/usr/local/share/GeoLiteCity.dat') > city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) > host = socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] > except Exception as e: > host = repr(e) > > > Sometimes though iam still receiving the usual > UnicodeDecodeError('utf-8', b'\xc1\xf0\xef\xf4\xf5 > > but only for a few ip addresses, in moste cases it works. And naturally, you now know how to debug those UnicodeDecodeError problems. Surely, the code you post here isn't what you actually do, because when people spend time to give you detailed advice, you actually read it, and work at understanding it. Chortle, snort. -- DaveA