UnicodeDecodeError issue

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Sep 1 04:35:12 EDT 2013


On Sat, 31 Aug 2013 23:50:23 -0700, Ferrous Cranus wrote:

> Τη Σάββατο, 31 Αυγούστου 2013 9:41:27 π.μ. UTC+3, ο χρήστης Ferrous
> Cranus έγραψε:
>> Suddenly my webiste superhost.gr running my main python script presents
>> 
>> me with this error:
>> 
>> 
>> 
>> Code:
>> 
>> UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3\xf4\xef
>> 
>> \xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2', 0, 1,
>> 
>> 'invalid start byte')
>> 
>> 
>> 
>> 
>> 
>> Does anyone know what this means?
>> 
>> 
>> 
>> 
>> 
>> --
>> 
>> Webhost <http://superhost.gr>
> 
> Good morning Steven,
> 
> Ye i'm aware that i need to define variables before i try to make use of
> them. I have study all of your examples and then re-view my code and i
> can *assure* you that the line statement that tied to set the 'host'
> variable is very early at the top of the script(of course after
> imports), and the cur.execute comes after.
> 
> The problem here is not what you say, that i try to drink k a coffee
> before actually making one first but rather than i cannot drink the
> coffee although i know *i have tried* to make one first.
> 
> 
> i will upload the code for you to prove my sayings at pastebin.
> 
> http://pastebin.com/J97guApQ


You are mistaken. In line 20-25, you have this:

try:
    gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')
    city = gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or
        gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] )
    host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
        socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] 
        or "Proxy Detected"
except Exception as e:
        print( repr(e), file=open( '/tmp/err.out', 'w' ) )


An error occurs inside that block, *before* host gets set. Who knows what 
the error is? You have access to the err.out file, but apparently you 
aren't reading it to find out.

Then, 110 lines later, at line 135, you try to access the value of "host" 
that never got set.

Your job is to read the error in /tmp/err.out, see what is failing, and 
fix it.


-- 
Steven



More information about the Python-list mailing list