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


Groups > comp.lang.python > #53416

Re: UnicodeDecodeError issue

From Ferrous Cranus <nikos@superhost.gr>
Newsgroups comp.lang.python
Subject Re: UnicodeDecodeError issue
Date 2013-09-01 17:25 +0300
Organization National Technical University of Athens, Greece
Message-ID <kvvioj$21rg$1@news.ntua.gr> (permalink)
References <kvs36n$3ap$1@news.grnet.gr> <ce40cfed-978b-41d6-9fca-c1a9d54855cf@googlegroups.com> <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> <kvvhoi$1v4o$1@news.ntua.gr>

Show all headers | View raw


Στις 1/9/2013 5:08 μμ, ο/η Ferrous Cranus έγραψε:
> Στις 1/9/2013 11:35 πμ, ο/η Steven D'Aprano έγραψε:
>> 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.
>>
>>
>
> But i'm Steven! That why i make use of it to read it immediately after
> my script run at browser time.
>
> i have even included a sys.exit(0) after the try:/except block:
>
> Here is it:
>
>
> errout = open( '/tmp/err.out', 'w' )        # opens and truncates the
> error output file
> 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( "Xyzzy exception-", repr( sys.exc_info() ), file=errout )
>      errout.flush()
>
> sys.exit(0)
>
> and the output of error file is:
>
>
> nikos@superhost.gr [~]# cat /tmp/err.out
> 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')
>


But i noticed that err.out and /usr/local/apache/logs/error_log produced 
different output.

In any case i check both:


nikos@superhost.gr [~]# chmod 777 /tmp/err2.out

ouput of error_log
nikos@superhost.gr [~]# [Sun Sep 01 14:23:46 2013] [error] [client 
173.245.49.120] Premature end of script headers: metrites.py
[Sun Sep 01 14:23:46 2013] [error] [client 173.245.49.120] File does not 
exist: /home/nikos/public_html/500.shtml



Also i have even changed output error filename.
turns out empty.

nikos@superhost.gr [~]# cat /tmp/err2.out

-- 
Webhost <http://superhost.gr>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-08-31 09:41 +0300
  Re: UnicodeDecodeError issue Chris Angelico <rosuav@gmail.com> - 2013-08-31 16:53 +1000
    Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-08-31 10:02 +0300
      Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-08-31 10:18 +0300
  Re: UnicodeDecodeError issue Peter Otten <__peter__@web.de> - 2013-08-31 09:25 +0200
    Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-08-31 10:58 +0300
      Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-08-31 11:31 +0300
        Re: UnicodeDecodeError issue Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-31 11:28 +0000
          Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-08-31 15:58 +0300
            Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-08-31 16:07 +0300
            Re: UnicodeDecodeError issue Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-31 15:44 +0000
  Re: UnicodeDecodeError issue Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-08-31 23:50 -0700
    Re: UnicodeDecodeError issue Chris Angelico <rosuav@gmail.com> - 2013-09-01 17:12 +1000
      Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-01 10:23 +0300
        Re: UnicodeDecodeError issue Chris Angelico <rosuav@gmail.com> - 2013-09-01 17:28 +1000
        Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-01 10:35 +0000
          Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-01 16:59 +0300
            Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-01 15:40 +0000
        Re: UnicodeDecodeError issue Chris Angelico <rosuav@gmail.com> - 2013-09-01 20:51 +1000
    Re: UnicodeDecodeError issue Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-01 08:35 +0000
      Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-01 17:08 +0300
        Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-01 17:25 +0300
        Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-01 15:36 +0000
          Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-01 19:10 +0300
            Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-02 01:23 +0300
              Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-01 23:14 +0000
                Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-02 07:16 +0300
                Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-02 11:38 +0000
                Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-02 14:49 +0300
                Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-02 12:21 +0000
                Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-02 18:05 +0300
                Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-02 18:28 +0000
                Re: UnicodeDecodeError issue Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-09-04 01:35 -0700
                Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-04 11:26 +0000
                Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-04 14:38 +0300
                Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-04 12:38 +0000
                Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-04 17:29 +0300
                Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-05 00:17 +0000
                Re: UnicodeDecodeError issue Steven D'Aprano <steve@pearwood.info> - 2013-09-05 03:07 +0000
                Re: UnicodeDecodeError issue Chris Angelico <rosuav@gmail.com> - 2013-09-05 13:59 +1000
                Re: UnicodeDecodeError issue Steven D'Aprano <steve@pearwood.info> - 2013-09-05 05:28 +0000
                Re: UnicodeDecodeError issue MRAB <python@mrabarnett.plus.com> - 2013-09-02 12:56 +0100
                Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-02 12:24 +0000
                Re: UnicodeDecodeError issue MRAB <python@mrabarnett.plus.com> - 2013-09-02 15:44 +0100
                Re: UnicodeDecodeError issue wxjmfauth@gmail.com - 2013-09-03 08:23 -0700
                Re: UnicodeDecodeError issue Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-04 10:01 +0200
                Re: UnicodeDecodeError issue wxjmfauth@gmail.com - 2013-09-04 07:08 -0700
                Re: UnicodeDecodeError issue Chris Angelico <rosuav@gmail.com> - 2013-09-03 08:45 +1000
                Re: UnicodeDecodeError issue Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-03 14:56 +0000
                Re: UnicodeDecodeError issue Joel Goldstick <joel.goldstick@gmail.com> - 2013-09-02 20:49 -0400

csiph-web