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


Groups > comp.lang.python > #49827 > unrolled thread

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

Started byΝίκος <nikos@superhost.gr>
First post2013-07-04 11:37 +0300
Last post2013-09-06 16:17 -0700
Articles 20 on this page of 68 — 16 participants

Back to article view | Back to comp.lang.python


Contents

  UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος <nikos@superhost.gr> - 2013-07-04 11:37 +0300
    Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Dave Angel <davea@davea.name> - 2013-07-04 05:59 -0400
      Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος <nikos@superhost.gr> - 2013-07-04 13:03 +0300
        Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Dave Angel <davea@davea.name> - 2013-07-04 06:29 -0400
          Fwd: Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος <nikos@superhost.gr> - 2013-07-04 13:36 +0300
    Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2013-07-04 11:50 +0200
      Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος <nikos@superhost.gr> - 2013-07-04 13:38 +0300
        Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Chris Angelico <rosuav@gmail.com> - 2013-07-04 20:54 +1000
          Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος <nikos@superhost.gr> - 2013-07-04 14:29 +0300
            Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte MRAB <python@mrabarnett.plus.com> - 2013-07-04 12:52 +0100
              Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος <nikos@superhost.gr> - 2013-07-04 15:06 +0300
            Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Chris Angelico <rosuav@gmail.com> - 2013-07-04 22:37 +1000
        Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte MRAB <python@mrabarnett.plus.com> - 2013-07-04 12:06 +0100
          Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος <nikos@superhost.gr> - 2013-07-04 14:36 +0300
            Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte MRAB <python@mrabarnett.plus.com> - 2013-07-04 13:07 +0100
              Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος <nikos@superhost.gr> - 2013-07-04 15:47 +0300
                Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte MRAB <python@mrabarnett.plus.com> - 2013-07-04 14:34 +0100
                  Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος Γκρ33κ <nikos@superhost.gr> - 2013-07-04 16:38 +0300
                  Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte MRAB <python@mrabarnett.plus.com> - 2013-07-04 16:10 +0100
                    Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος Γκρ33κ <nikos@superhost.gr> - 2013-07-04 18:56 +0300
                      Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Wayne Werner <wayne@waynewerner.com> - 2013-07-12 06:47 -0500
                        Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Ferrous Cranus <nikos@superhost.gr> - 2013-07-12 14:56 +0300
                          Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Dave Angel <davea@davea.name> - 2013-07-12 11:46 -0400
              Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος <nikos@superhost.gr> - 2013-07-04 15:52 +0300
                Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte MRAB <python@mrabarnett.plus.com> - 2013-07-04 14:34 +0100
                  Fwd: Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος Γκρ33κ <nikos@superhost.gr> - 2013-07-04 17:48 +0300
        Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2013-07-04 15:07 +0200
          Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος Γκρ33κ <nikos@superhost.gr> - 2013-07-04 16:26 +0300
        Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-07-04 16:08 -0400
          Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Ferrous Cranus <nikos@superhost.gr> - 2013-07-04 23:25 +0300
            Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Lele Gaifax <lele@metapensiero.it> - 2013-07-04 22:44 +0200
            Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Michael Torrie <torriem@gmail.com> - 2013-07-04 14:53 -0600
        Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Nobody <nobody@nowhere.com> - 2013-07-05 01:06 +0100
          Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Ferrous Cranus <nikos@superhost.gr> - 2013-07-05 09:07 +0300
            Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Lele Gaifax <lele@metapensiero.it> - 2013-07-05 08:55 +0200
              Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος Gr33k <nikos@superhost.gr> - 2013-07-05 10:10 +0300
          Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος Gr33k <nikos@superhost.gr> - 2013-07-05 09:51 +0300
            Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Lele Gaifax <lele@metapensiero.it> - 2013-07-05 09:06 +0200
              Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος Gr33k <nikos@superhost.gr> - 2013-07-05 10:13 +0300
                Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Dave Angel <davea@davea.name> - 2013-07-05 04:27 -0400
                  Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος Gr33k <nikos@superhost.gr> - 2013-07-05 12:01 +0300
            Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Benjamin Kaplan <benjamin.kaplan@case.edu> - 2013-07-05 00:21 -0700
            Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Dave Angel <davea@davea.name> - 2013-07-05 03:50 -0400
              Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος Gr33k <nikos@superhost.gr> - 2013-07-05 11:00 +0300
                Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Dave Angel <davea@davea.name> - 2013-07-05 04:35 -0400
                  Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος Gr33k <nikos@superhost.gr> - 2013-07-05 11:49 +0300
                    Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Dave Angel <davea@davea.name> - 2013-07-05 05:21 -0400
                      Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος Gr33k <nikos@superhost.gr> - 2013-07-05 12:25 +0300
                        Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Lele Gaifax <lele@metapensiero.it> - 2013-07-05 12:24 +0200
                          Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος Gr33k <nikos@superhost.gr> - 2013-07-05 13:28 +0300
                        Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος Gr33k <nikos@superhost.gr> - 2013-07-05 13:26 +0300
                          Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Lele Gaifax <lele@metapensiero.it> - 2013-07-05 12:36 +0200
                            Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος Gr33k <nikos@superhost.gr> - 2013-07-05 13:42 +0300
                              Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Lele Gaifax <lele@metapensiero.it> - 2013-07-05 12:59 +0200
                                Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος Gr33k <nikos@superhost.gr> - 2013-07-05 14:05 +0300
                                  Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος Gr33k <nikos@superhost.gr> - 2013-07-05 14:16 +0300
                                  Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Lele Gaifax <lele@metapensiero.it> - 2013-07-05 13:16 +0200
                                    Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος Gr33k <nikos@superhost.gr> - 2013-07-05 14:27 +0300
                                      Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte feedthetroll@gmx.de - 2013-07-05 05:06 -0700
                      Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος Gr33k <nikos@superhost.gr> - 2013-07-05 13:33 +0300
                        Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte feedthetroll@gmx.de - 2013-07-05 04:56 -0700
                          Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte feedthetroll@gmx.de - 2013-07-05 05:14 -0700
                        Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Dave Angel <davea@davea.name> - 2013-07-05 09:05 -0400
                        Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Lele Gaifax <lele@metapensiero.it> - 2013-07-05 16:11 +0200
                          Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Νίκος Gr33k <nikos@superhost.gr> - 2013-07-05 17:27 +0300
                Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte feedthetroll@gmx.de - 2013-07-05 01:44 -0700
            Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Lele Gaifax <lele@metapensiero.it> - 2013-07-05 12:16 +0200
    Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte roggero.n@gmail.com - 2013-09-06 16:17 -0700

Page 1 of 4  [1] 2 3 4  Next page →


#49827 — UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

FromΝίκος <nikos@superhost.gr>
Date2013-07-04 11:37 +0300
SubjectUnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte
Message-ID<kr3c7k$tjs$2@news.grnet.gr>
I just started to have this error without changing nothing

in my index.html(template) and metrites.py(which ipen the template)

[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Original 
exception was:
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Traceback 
(most recent call last):
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97]   File 
"/home/nikos/public_html/cgi-bin/metrites.py", line 19, in <module>
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97]     host = 
socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 'UnResolved'
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] 
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: 
invalid start byte
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Premature end 
of script headers: metrites.py


Why cant it decode the starting byte? what starting byte is that?
-- 
What is now proved was at first only imagined!

[toc] | [next] | [standalone]


#49831

FromDave Angel <davea@davea.name>
Date2013-07-04 05:59 -0400
Message-ID<mailman.4214.1372931978.3114.python-list@python.org>
In reply to#49827
On 07/04/2013 04:37 AM, Νίκος wrote:
> I just started to have this error without changing nothing
>
> in my index.html(template) and metrites.py(which ipen the template)
>
> [Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Original
> exception was: [Thu Jul 04 11:35:14 2013] [error] [client
> 108.162.229.97] Traceback (most recent call last): [Thu Jul 04
> 11:35:14 2013] [error] [client 108.162.229.97]   File
> "/home/nikos/public_html/cgi-bin/metrites.py", line 19, in <module>
> [Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97]     host =
>  socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
> 'UnResolved' [Thu Jul 04 11:35:14 2013] [error] [client
> 108.162.229.97] UnicodeDecodeError: 'utf-8' codec can't decode byte
> 0xb6 in position 0: invalid start byte [Thu Jul 04 11:35:14 2013]
> [error] [client 108.162.229.97] Premature end of script headers:
> metrites.py
>
>
> Why cant it decode the starting byte? what starting byte is that?

The error message means that somebody is trying to decode a byte string
into Unicode, and using the utf-8 codec for it.  Only certain sequences
are legal in utf-8, and the first byte of a character may not be 0xb6.
So it gives an error.  The question is where does this string come from.


Well, the message shows the source line from metrites.py:

host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 'UnResolved'

So the most likely candidate is the string in the environment named
"REMOTE_ADDR"  Can you display that string?  it should look like

"11.24.32.4"

or some other valid IP address.


I'm assuming Python 2.7.  You should specify the python version when 
starting a new thread, as we (or at least I) cannot keep track of what 
version everyone's running.




-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#49833

FromΝίκος <nikos@superhost.gr>
Date2013-07-04 13:03 +0300
Message-ID<kr3hab$jn0$1@news.grnet.gr>
In reply to#49831
Στις 4/7/2013 12:59 μμ, ο/η Dave Angel έγραψε:
> On 07/04/2013 04:37 AM, Νίκος wrote:
>> I just started to have this error without changing nothing
>>
>> in my index.html(template) and metrites.py(which ipen the template)
>>
>> [Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Original
>> exception was: [Thu Jul 04 11:35:14 2013] [error] [client
>> 108.162.229.97] Traceback (most recent call last): [Thu Jul 04
>> 11:35:14 2013] [error] [client 108.162.229.97]   File
>> "/home/nikos/public_html/cgi-bin/metrites.py", line 19, in <module>
>> [Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97]     host =
>>  socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
>> 'UnResolved' [Thu Jul 04 11:35:14 2013] [error] [client
>> 108.162.229.97] UnicodeDecodeError: 'utf-8' codec can't decode byte
>> 0xb6 in position 0: invalid start byte [Thu Jul 04 11:35:14 2013]
>> [error] [client 108.162.229.97] Premature end of script headers:
>> metrites.py
>>
>>
>> Why cant it decode the starting byte? what starting byte is that?
>
> The error message means that somebody is trying to decode a byte string
> into Unicode, and using the utf-8 codec for it.  Only certain sequences
> are legal in utf-8, and the first byte of a character may not be 0xb6.
> So it gives an error.  The question is where does this string come from.
>
>
> Well, the message shows the source line from metrites.py:
>
> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 'UnResolved'
>
> So the most likely candidate is the string in the environment named
> "REMOTE_ADDR"  Can you display that string?  it should look like
>
> "11.24.32.4"
>
> or some other valid IP address.
>
>
> I'm assuming Python 2.7.  You should specify the python version when
> starting a new thread, as we (or at least I) cannot keep track of what
> version everyone's running.

Ima using Python v3.3.2 Dave

The host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 
'UnResolved' should not have give an error since i explicityl tell it 
that if it cannot resolve dns the ip to hostname to set it as "unresolved"

The error appear ONLY when i CloudFlare superhost.gr

If i pause tthe domain form CloudFlare then my website loads properly.


-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#49836

FromDave Angel <davea@davea.name>
Date2013-07-04 06:29 -0400
Message-ID<mailman.4216.1372933781.3114.python-list@python.org>
In reply to#49833
On 07/04/2013 06:03 AM, Νίκος wrote:
> Στις 4/7/2013 12:59 μμ, ο/η Dave Angel έγραψε:
>> On 07/04/2013 04:37 AM, Νίκος wrote:
>>> I just started to have this error without changing nothing
>>>
>>> in my index.html(template) and metrites.py(which ipen the template)
>>>
>>> [Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Original
>>> exception was: [Thu Jul 04 11:35:14 2013] [error] [client
>>> 108.162.229.97] Traceback (most recent call last): [Thu Jul 04
>>> 11:35:14 2013] [error] [client 108.162.229.97]   File
>>> "/home/nikos/public_html/cgi-bin/metrites.py", line 19, in <module>
>>> [Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97]     host =
>>>  socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
>>> 'UnResolved' [Thu Jul 04 11:35:14 2013] [error] [client
>>> 108.162.229.97] UnicodeDecodeError: 'utf-8' codec can't decode byte
>>> 0xb6 in position 0: invalid start byte [Thu Jul 04 11:35:14 2013]
>>> [error] [client 108.162.229.97] Premature end of script headers:
>>> metrites.py
>>>
>>>
>>> Why cant it decode the starting byte? what starting byte is that?
>>
>> The error message means that somebody is trying to decode a byte string
>> into Unicode, and using the utf-8 codec for it.  Only certain sequences
>> are legal in utf-8, and the first byte of a character may not be 0xb6.
>> So it gives an error.  The question is where does this string come from.
>>
>>
>> Well, the message shows the source line from metrites.py:
>>
>> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
>> 'UnResolved'
>>
>> So the most likely candidate is the string in the environment named
>> "REMOTE_ADDR"  Can you display that string?  it should look like
>>
>> "11.24.32.4"
>>
>> or some other valid IP address.
>>
>>
>> I'm assuming Python 2.7.  You should specify the python version when
>> starting a new thread, as we (or at least I) cannot keep track of what
>> version everyone's running.
>
> Ima using Python v3.3.2 Dave
>
> The host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
> 'UnResolved' should not have give an error since i explicityl tell it
> that if it cannot resolve dns the ip to hostname to set it as "unresolved"

That's not true.  The 'or' doesn't get executed until after the 
gethostbyaddr() call has returned.  So if something's wrong with that 
call, and it throws an exception, the 'or "unresolved"' won't help.

I don't know that this is the problem, and I'm not all familiar with 
these api's.  But I cannot see anything else that could go wrong there 
to give that particular exception.  Unless the hostname it's going to 
return is a byte string.

>
> The error appear ONLY when i CloudFlare superhost.gr
>
> If i pause tthe domain form CloudFlare then my website loads properly.
>
>

I don't really know what CloudFlare is, and have no idea what 'pausing 
the form' will do.  But since it has something to do with dns, perhaps 
it's returning an invalid host name, one that isn't encoded in utf-8.

-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#49837

FromΝίκος <nikos@superhost.gr>
Date2013-07-04 13:36 +0300
Message-ID<kr3j71$jn0$3@news.grnet.gr>
In reply to#49836


-------- Αρχικό μήνυμα --------
Θέμα: Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in 
position 0: invalid start byte
Ημερομηνία: Thu, 04 Jul 2013 06:29:25 -0400
Από: Dave Angel <davea@davea.name>
Προς: python-list@python.org
Ομάδες συζήτησης: comp.lang.python
Αναφορές: <kr3c7k$tjs$2@news.grnet.gr> 
<mailman.4214.1372931978.3114.python-list@python.org> 
<kr3hab$jn0$1@news.grnet.gr>

On 07/04/2013 06:03 AM, Νίκος wrote:
> Στις 4/7/2013 12:59 μμ, ο/η Dave Angel έγραψε:
>> On 07/04/2013 04:37 AM, Νίκος wrote:
>>> I just started to have this error without changing nothing
>>>
>>> in my index.html(template) and metrites.py(which ipen the template)
>>>
>>> [Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Original
>>> exception was: [Thu Jul 04 11:35:14 2013] [error] [client
>>> 108.162.229.97] Traceback (most recent call last): [Thu Jul 04
>>> 11:35:14 2013] [error] [client 108.162.229.97]   File
>>> "/home/nikos/public_html/cgi-bin/metrites.py", line 19, in <module>
>>> [Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97]     host =
>>>  socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
>>> 'UnResolved' [Thu Jul 04 11:35:14 2013] [error] [client
>>> 108.162.229.97] UnicodeDecodeError: 'utf-8' codec can't decode byte
>>> 0xb6 in position 0: invalid start byte [Thu Jul 04 11:35:14 2013]
>>> [error] [client 108.162.229.97] Premature end of script headers:
>>> metrites.py
>>>
>>>
>>> Why cant it decode the starting byte? what starting byte is that?
>>
>> The error message means that somebody is trying to decode a byte string
>> into Unicode, and using the utf-8 codec for it.  Only certain sequences
>> are legal in utf-8, and the first byte of a character may not be 0xb6.
>> So it gives an error.  The question is where does this string come from.
>>
>>
>> Well, the message shows the source line from metrites.py:
>>
>> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
>> 'UnResolved'
>>
>> So the most likely candidate is the string in the environment named
>> "REMOTE_ADDR"  Can you display that string?  it should look like
>>
>> "11.24.32.4"
>>
>> or some other valid IP address.
>>
>>
>> I'm assuming Python 2.7.  You should specify the python version when
>> starting a new thread, as we (or at least I) cannot keep track of what
>> version everyone's running.
>
> Ima using Python v3.3.2 Dave
>
> The host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
> 'UnResolved' should not have give an error since i explicityl tell it
> that if it cannot resolve dns the ip to hostname to set it as "unresolved"

That's not true.  The 'or' doesn't get executed until after the
gethostbyaddr() call has returned.  So if something's wrong with that
call, and it throws an exception, the 'or "unresolved"' won't help.

So how do you propose to write the above statement?
I was under the i impression then if for any reason the gethostbyaddr 
failed then or's argument will be returned instead.

>
> The error appear ONLY when i CloudFlare superhost.gr
>
> If i pause tthe domain form CloudFlare then my website loads properly.
>
>

I don't really know what CloudFlare is, and have no idea what 'pausing
the form' will do.  But since it has something to do with dns, perhaps
it's returning an invalid host name, one that isn't encoded in utf-8.

I think so too.

-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#49835

FromUlrich Eckhardt <ulrich.eckhardt@dominolaser.com>
Date2013-07-04 11:50 +0200
Message-ID<n3tfaa-eqh.ln1@satorlaser.homedns.org>
In reply to#49827
Am 04.07.2013 10:37, schrieb Νίκος:
> I just started to have this error without changing nothing

Well, undo the nothing that you didn't change. ;)

> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0:
> invalid start byte
> [Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Premature end
> of script headers: metrites.py
>
> Why cant it decode the starting byte? what starting byte is that?

It's the 0xb6 but it's expecting the starting byte of a UTF-8 sequence. 
Please do some research on UTF-8, that should clear it up. You could 
also search for common causes of that error.

Uli

[toc] | [prev] | [next] | [standalone]


#49838

FromΝίκος <nikos@superhost.gr>
Date2013-07-04 13:38 +0300
Message-ID<kr3jai$jn0$4@news.grnet.gr>
In reply to#49835
Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:
> Am 04.07.2013 10:37, schrieb Νίκος:
>> I just started to have this error without changing nothing
>
> Well, undo the nothing that you didn't change. ;)
>
>> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0:
>> invalid start byte
>> [Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Premature end
>> of script headers: metrites.py
>>
>> Why cant it decode the starting byte? what starting byte is that?
>
> It's the 0xb6 but it's expecting the starting byte of a UTF-8 sequence.
> Please do some research on UTF-8, that should clear it up. You could
> also search for common causes of that error.

So you are also suggesting that what gesthostbyaddr() returns is not 
utf-8 encoded too?

What character is 0xb6 anyways?

-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#49839

FromChris Angelico <rosuav@gmail.com>
Date2013-07-04 20:54 +1000
Message-ID<mailman.4217.1372935585.3114.python-list@python.org>
In reply to#49838
On Thu, Jul 4, 2013 at 8:38 PM, Νίκος <nikos@superhost.gr> wrote:
> So you are also suggesting that what gesthostbyaddr() returns is not utf-8
> encoded too?
>
> What character is 0xb6 anyways?

It isn't. It's a byte. Bytes are not characters.

http://www.joelonsoftware.com/articles/Unicode.html

ChrisA

[toc] | [prev] | [next] | [standalone]


#49843

FromΝίκος <nikos@superhost.gr>
Date2013-07-04 14:29 +0300
Message-ID<kr3mai$jn0$5@news.grnet.gr>
In reply to#49839
Στις 4/7/2013 1:54 μμ, ο/η Chris Angelico έγραψε:
> On Thu, Jul 4, 2013 at 8:38 PM, ����� <nikos@superhost.gr> wrote:
>> So you are also suggesting that what gesthostbyaddr() returns is not utf-8
>> encoded too?
>>
>> What character is 0xb6 anyways?
>
> It isn't. It's a byte. Bytes are not characters.
>
> http://www.joelonsoftware.com/articles/Unicode.html

Well in case of utf-8 encoding for the first 127 codepoing we can safely 
say that a character equals a byte :)

-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#49845

FromMRAB <python@mrabarnett.plus.com>
Date2013-07-04 12:52 +0100
Message-ID<mailman.4221.1372938733.3114.python-list@python.org>
In reply to#49843
On 04/07/2013 12:29, Νίκος wrote:
> Στις 4/7/2013 1:54 μμ, ο/η Chris Angelico έγραψε:
>> On Thu, Jul 4, 2013 at 8:38 PM, ����� <nikos@superhost.gr> wrote:
>>> So you are also suggesting that what gesthostbyaddr() returns is not utf-8
>>> encoded too?
>>>
>>> What character is 0xb6 anyways?
>>
>> It isn't. It's a byte. Bytes are not characters.
>>
>> http://www.joelonsoftware.com/articles/Unicode.html
>
> Well in case of utf-8 encoding for the first 127 codepoing we can safely
> say that a character equals a byte :)
>
Equals? No. Bytes are not characters. (Strictly speaking, they're
codepoints, not characters.)

And anyway, it's the first _128_ codepoints.

[toc] | [prev] | [next] | [standalone]


#49846

FromΝίκος <nikos@superhost.gr>
Date2013-07-04 15:06 +0300
Message-ID<kr3ogn$1ko$1@news.grnet.gr>
In reply to#49845
Στις 4/7/2013 2:52 μμ, ο/η MRAB έγραψε:
> On 04/07/2013 12:29, Νίκος wrote:
>> Στις 4/7/2013 1:54 μμ, ο/η Chris Angelico έγραψε:
>>> On Thu, Jul 4, 2013 at 8:38 PM, ����� <nikos@superhost.gr> wrote:
>>>> So you are also suggesting that what gesthostbyaddr() returns is not
>>>> utf-8
>>>> encoded too?
>>>>
>>>> What character is 0xb6 anyways?
>>>
>>> It isn't. It's a byte. Bytes are not characters.
>>>
>>> http://www.joelonsoftware.com/articles/Unicode.html
>>
>> Well in case of utf-8 encoding for the first 127 codepoing we can safely
>> say that a character equals a byte :)
>>
> Equals? No. Bytes are not characters. (Strictly speaking, they're
> codepoints, not characters.)
>
> And anyway, it's the first _128_ codepoints.

Yes 0-127 = 128, i knew that!

Well the relationship between characters and bytes is that:

A [0-127] Unicode codepoints(characters) need 1-byte to be stored in 
utf-8 encoding.

I think its also correct to say that the byte in the above situation is 
the representation of our character.

-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#49849

FromChris Angelico <rosuav@gmail.com>
Date2013-07-04 22:37 +1000
Message-ID<mailman.4224.1372941469.3114.python-list@python.org>
In reply to#49843
On Thu, Jul 4, 2013 at 9:52 PM, MRAB <python@mrabarnett.plus.com> wrote:
> On 04/07/2013 12:29, Νίκος wrote:
>>
>> Στις 4/7/2013 1:54 μμ, ο/η Chris Angelico έγραψε:
>>>
>>> On Thu, Jul 4, 2013 at 8:38 PM, ����� <nikos@superhost.gr> wrote:
>>>>
>>>> So you are also suggesting that what gesthostbyaddr() returns is not
>>>> utf-8
>>>> encoded too?
>>>>
>>>> What character is 0xb6 anyways?
>>>
>>>
>>> It isn't. It's a byte. Bytes are not characters.
>>>
>>> http://www.joelonsoftware.com/articles/Unicode.html
>>
>>
>> Well in case of utf-8 encoding for the first 127 codepoing we can safely
>> say that a character equals a byte :)
>>
> Equals? No. Bytes are not characters. (Strictly speaking, they're
> codepoints, not characters.)
>
> And anyway, it's the first _128_ codepoints.

As MRAB says, even if there's a 1:1 correspondence between bytes,
codepoints, and characters, they're still not the same thing. Plus,
0xb6 is not in the first 128, so your statement is false and your
question has no answer. Do you understand why I gave you that link? If
not, go read the page linked to.

ChrisA

[toc] | [prev] | [next] | [standalone]


#49841

FromMRAB <python@mrabarnett.plus.com>
Date2013-07-04 12:06 +0100
Message-ID<mailman.4219.1372935984.3114.python-list@python.org>
In reply to#49838
On 04/07/2013 11:38, Νίκος wrote:
> Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:
>> Am 04.07.2013 10:37, schrieb Νίκος:
>>> I just started to have this error without changing nothing
>>
>> Well, undo the nothing that you didn't change. ;)
>>
>>> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0:
>>> invalid start byte
>>> [Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Premature end
>>> of script headers: metrites.py
>>>
>>> Why cant it decode the starting byte? what starting byte is that?
>>
>> It's the 0xb6 but it's expecting the starting byte of a UTF-8 sequence.
>> Please do some research on UTF-8, that should clear it up. You could
>> also search for common causes of that error.
>
> So you are also suggesting that what gesthostbyaddr() returns is not
> utf-8 encoded too?
>
> What character is 0xb6 anyways?
>
Well, it's from a bytestring, so you'll have to specify what encoding
you're using! (It clearly isn't UTF-8.)

If it's ISO-8859-7 (what you've previously referred to as "greek-iso"),
then:

 >>> import unicodedata
 >>> unicodedata.name(b"\xb6".decode("ISO-8859-7"))
'GREEK CAPITAL LETTER ALPHA WITH TONOS'

You'll need to find out where that bytestring is coming from.

[toc] | [prev] | [next] | [standalone]


#49844

FromΝίκος <nikos@superhost.gr>
Date2013-07-04 14:36 +0300
Message-ID<kr3mnq$jn0$6@news.grnet.gr>
In reply to#49841
Στις 4/7/2013 2:06 μμ, ο/η MRAB έγραψε:
> On 04/07/2013 11:38, Νίκος wrote:
>> Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:
>>> Am 04.07.2013 10:37, schrieb Νίκος:
>>>> I just started to have this error without changing nothing
>>>
>>> Well, undo the nothing that you didn't change. ;)
>>>
>>>> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0:
>>>> invalid start byte
>>>> [Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Premature
>>>> end
>>>> of script headers: metrites.py
>>>>
>>>> Why cant it decode the starting byte? what starting byte is that?
>>>
>>> It's the 0xb6 but it's expecting the starting byte of a UTF-8 sequence.
>>> Please do some research on UTF-8, that should clear it up. You could
>>> also search for common causes of that error.
>>
>> So you are also suggesting that what gesthostbyaddr() returns is not
>> utf-8 encoded too?
>>
>> What character is 0xb6 anyways?
>>
> Well, it's from a bytestring, so you'll have to specify what encoding
> you're using! (It clearly isn't UTF-8.)
>
> If it's ISO-8859-7 (what you've previously referred to as "greek-iso"),
> then:
>
>  >>> import unicodedata
>  >>> unicodedata.name(b"\xb6".decode("ISO-8859-7"))
> 'GREEK CAPITAL LETTER ALPHA WITH TONOS'
>
> You'll need to find out where that bytestring is coming from.

Right.
But nowhere in my script(metrites.py) i use an 'Ά' so i really have no 
clue where this is coming from.

And you are right if it was a byte came from an utf-8 encoding scheme 
then it would be automatically decoded.

The only thing i can say for use is that this problem a[[ear only when i 
cloudflare my domain "superhost.gr"

If i un-cloudlflare it it cease to display errors.

Can you tell me hpw to write the following properly:

host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 'UnResolved'

so even if the function fails "unresolved" to be returned back?
Somehow i need to capture the error.

Or it dosnt have to do it the or operand will be returned?



-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#49847

FromMRAB <python@mrabarnett.plus.com>
Date2013-07-04 13:07 +0100
Message-ID<mailman.4222.1372939645.3114.python-list@python.org>
In reply to#49844
On 04/07/2013 12:36, Νίκος wrote:
> Στις 4/7/2013 2:06 μμ, ο/η MRAB έγραψε:
>> On 04/07/2013 11:38, Νίκος wrote:
>>> Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:
>>>> Am 04.07.2013 10:37, schrieb Νίκος:
>>>>> I just started to have this error without changing nothing
>>>>
>>>> Well, undo the nothing that you didn't change. ;)
>>>>
>>>>> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0:
>>>>> invalid start byte
>>>>> [Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Premature
>>>>> end
>>>>> of script headers: metrites.py
>>>>>
>>>>> Why cant it decode the starting byte? what starting byte is that?
>>>>
>>>> It's the 0xb6 but it's expecting the starting byte of a UTF-8 sequence.
>>>> Please do some research on UTF-8, that should clear it up. You could
>>>> also search for common causes of that error.
>>>
>>> So you are also suggesting that what gesthostbyaddr() returns is not
>>> utf-8 encoded too?
>>>
>>> What character is 0xb6 anyways?
>>>
>> Well, it's from a bytestring, so you'll have to specify what encoding
>> you're using! (It clearly isn't UTF-8.)
>>
>> If it's ISO-8859-7 (what you've previously referred to as "greek-iso"),
>> then:
>>
>>  >>> import unicodedata
>>  >>> unicodedata.name(b"\xb6".decode("ISO-8859-7"))
>> 'GREEK CAPITAL LETTER ALPHA WITH TONOS'
>>
>> You'll need to find out where that bytestring is coming from.
>
> Right.
> But nowhere in my script(metrites.py) i use an 'Ά' so i really have no
> clue where this is coming from.
>
> And you are right if it was a byte came from an utf-8 encoding scheme
> then it would be automatically decoded.
>
> The only thing i can say for use is that this problem a[[ear only when i
> cloudflare my domain "superhost.gr"
>
> If i un-cloudlflare it it cease to display errors.
>
> Can you tell me hpw to write the following properly:
>
> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 'UnResolved'
>
> so even if the function fails "unresolved" to be returned back?
> Somehow i need to capture the error.
>
> Or it dosnt have to do it the or operand will be returned?
>
If gethostbyaddr fails, it raises socket.gaierror, (which, from Python
3.3 onwards, is a subclass of OSError), so try catching that, setting
'host' to 'UnResolved' if it's raised.

Also, try printing out ascii(os.environ['REMOTE_ADDR']).

[toc] | [prev] | [next] | [standalone]


#49851

FromΝίκος <nikos@superhost.gr>
Date2013-07-04 15:47 +0300
Message-ID<kr3qss$9h4$1@news.grnet.gr>
In reply to#49847
Στις 4/7/2013 3:07 μμ, ο/η MRAB έγραψε:
> On 04/07/2013 12:36, Νίκος wrote:
>> Στις 4/7/2013 2:06 μμ, ο/η MRAB έγραψε:
>>> On 04/07/2013 11:38, Νίκος wrote:
>>>> Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:
>>>>> Am 04.07.2013 10:37, schrieb Νίκος:
>>>>>> I just started to have this error without changing nothing
>>>>>
>>>>> Well, undo the nothing that you didn't change. ;)
>>>>>
>>>>>> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in
>>>>>> position 0:
>>>>>> invalid start byte
>>>>>> [Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Premature
>>>>>> end
>>>>>> of script headers: metrites.py
>>>>>>
>>>>>> Why cant it decode the starting byte? what starting byte is that?
>>>>>
>>>>> It's the 0xb6 but it's expecting the starting byte of a UTF-8
>>>>> sequence.
>>>>> Please do some research on UTF-8, that should clear it up. You could
>>>>> also search for common causes of that error.
>>>>
>>>> So you are also suggesting that what gesthostbyaddr() returns is not
>>>> utf-8 encoded too?
>>>>
>>>> What character is 0xb6 anyways?
>>>>
>>> Well, it's from a bytestring, so you'll have to specify what encoding
>>> you're using! (It clearly isn't UTF-8.)
>>>
>>> If it's ISO-8859-7 (what you've previously referred to as "greek-iso"),
>>> then:
>>>
>>>  >>> import unicodedata
>>>  >>> unicodedata.name(b"\xb6".decode("ISO-8859-7"))
>>> 'GREEK CAPITAL LETTER ALPHA WITH TONOS'
>>>
>>> You'll need to find out where that bytestring is coming from.
>>
>> Right.
>> But nowhere in my script(metrites.py) i use an 'Ά' so i really have no
>> clue where this is coming from.
>>
>> And you are right if it was a byte came from an utf-8 encoding scheme
>> then it would be automatically decoded.
>>
>> The only thing i can say for use is that this problem a[[ear only when i
>> cloudflare my domain "superhost.gr"
>>
>> If i un-cloudlflare it it cease to display errors.
>>
>> Can you tell me hpw to write the following properly:
>>
>> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
>> 'UnResolved'
>>
>> so even if the function fails "unresolved" to be returned back?
>> Somehow i need to capture the error.
>>
>> Or it dosnt have to do it the or operand will be returned?
>>
> If gethostbyaddr fails, it raises socket.gaierror, (which, from Python
> 3.3 onwards, is a subclass of OSError), so try catching that, setting
> 'host' to 'UnResolved' if it's raised.
>
> Also, try printing out ascii(os.environ['REMOTE_ADDR']).
>

I have followed your suggestion by trying this:

try:
	host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
except socket.gaierror:
	host = "UnResolved"

and then re-cloudlflared "superhost.gr" domain

http://superhost.gr/ gives internal server error.

-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#49861

FromMRAB <python@mrabarnett.plus.com>
Date2013-07-04 14:34 +0100
Message-ID<mailman.4229.1372944863.3114.python-list@python.org>
In reply to#49851
On 04/07/2013 13:47, Νίκος wrote:
> Στις 4/7/2013 3:07 μμ, ο/η MRAB έγραψε:
>> On 04/07/2013 12:36, Νίκος wrote:
>>> Στις 4/7/2013 2:06 μμ, ο/η MRAB έγραψε:
>>>> On 04/07/2013 11:38, Νίκος wrote:
>>>>> Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:
>>>>>> Am 04.07.2013 10:37, schrieb Νίκος:
>>>>>>> I just started to have this error without changing nothing
>>>>>>
>>>>>> Well, undo the nothing that you didn't change. ;)
>>>>>>
>>>>>>> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in
>>>>>>> position 0:
>>>>>>> invalid start byte
>>>>>>> [Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Premature
>>>>>>> end
>>>>>>> of script headers: metrites.py
>>>>>>>
>>>>>>> Why cant it decode the starting byte? what starting byte is that?
>>>>>>
>>>>>> It's the 0xb6 but it's expecting the starting byte of a UTF-8
>>>>>> sequence.
>>>>>> Please do some research on UTF-8, that should clear it up. You could
>>>>>> also search for common causes of that error.
>>>>>
>>>>> So you are also suggesting that what gesthostbyaddr() returns is not
>>>>> utf-8 encoded too?
>>>>>
>>>>> What character is 0xb6 anyways?
>>>>>
>>>> Well, it's from a bytestring, so you'll have to specify what encoding
>>>> you're using! (It clearly isn't UTF-8.)
>>>>
>>>> If it's ISO-8859-7 (what you've previously referred to as "greek-iso"),
>>>> then:
>>>>
>>>>  >>> import unicodedata
>>>>  >>> unicodedata.name(b"\xb6".decode("ISO-8859-7"))
>>>> 'GREEK CAPITAL LETTER ALPHA WITH TONOS'
>>>>
>>>> You'll need to find out where that bytestring is coming from.
>>>
>>> Right.
>>> But nowhere in my script(metrites.py) i use an 'Ά' so i really have no
>>> clue where this is coming from.
>>>
>>> And you are right if it was a byte came from an utf-8 encoding scheme
>>> then it would be automatically decoded.
>>>
>>> The only thing i can say for use is that this problem a[[ear only when i
>>> cloudflare my domain "superhost.gr"
>>>
>>> If i un-cloudlflare it it cease to display errors.
>>>
>>> Can you tell me hpw to write the following properly:
>>>
>>> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
>>> 'UnResolved'
>>>
>>> so even if the function fails "unresolved" to be returned back?
>>> Somehow i need to capture the error.
>>>
>>> Or it dosnt have to do it the or operand will be returned?
>>>
>> If gethostbyaddr fails, it raises socket.gaierror, (which, from Python
>> 3.3 onwards, is a subclass of OSError), so try catching that, setting
>> 'host' to 'UnResolved' if it's raised.
>>
>> Also, try printing out ascii(os.environ['REMOTE_ADDR']).
>>
>
> I have followed your suggestion by trying this:
>
> try:
> 	host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
> except socket.gaierror:
> 	host = "UnResolved"
>
> and then re-cloudlflared "superhost.gr" domain
>
> http://superhost.gr/ gives internal server error.
>
Try catching OSError instead. (As I said, from Python 3.3,
socket.gaierror is a subclass of it.)

[toc] | [prev] | [next] | [standalone]


#49867

FromΝίκος Γκρ33κ <nikos@superhost.gr>
Date2013-07-04 16:38 +0300
Message-ID<mailman.4232.1372947422.3114.python-list@python.org>
In reply to#49861
Στις 4/7/2013 4:34 μμ, ο/η MRAB έγραψε:
> On 04/07/2013 13:47, Νίκος wrote:
>> Στις 4/7/2013 3:07 μμ, ο/η MRAB έγραψε:
>>> On 04/07/2013 12:36, Νίκος wrote:
>>>> Στις 4/7/2013 2:06 μμ, ο/η MRAB έγραψε:
>>>>> On 04/07/2013 11:38, Νίκος wrote:
>>>>>> Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:
>>>>>>> Am 04.07.2013 10:37, schrieb Νίκος:
>>>>>>>> I just started to have this error without changing nothing
>>>>>>>
>>>>>>> Well, undo the nothing that you didn't change. ;)
>>>>>>>
>>>>>>>> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in
>>>>>>>> position 0:
>>>>>>>> invalid start byte
>>>>>>>> [Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97]
>>>>>>>> Premature
>>>>>>>> end
>>>>>>>> of script headers: metrites.py
>>>>>>>>
>>>>>>>> Why cant it decode the starting byte? what starting byte is that?
>>>>>>>
>>>>>>> It's the 0xb6 but it's expecting the starting byte of a UTF-8
>>>>>>> sequence.
>>>>>>> Please do some research on UTF-8, that should clear it up. You could
>>>>>>> also search for common causes of that error.
>>>>>>
>>>>>> So you are also suggesting that what gesthostbyaddr() returns is not
>>>>>> utf-8 encoded too?
>>>>>>
>>>>>> What character is 0xb6 anyways?
>>>>>>
>>>>> Well, it's from a bytestring, so you'll have to specify what encoding
>>>>> you're using! (It clearly isn't UTF-8.)
>>>>>
>>>>> If it's ISO-8859-7 (what you've previously referred to as
>>>>> "greek-iso"),
>>>>> then:
>>>>>
>>>>>  >>> import unicodedata
>>>>>  >>> unicodedata.name(b"\xb6".decode("ISO-8859-7"))
>>>>> 'GREEK CAPITAL LETTER ALPHA WITH TONOS'
>>>>>
>>>>> You'll need to find out where that bytestring is coming from.
>>>>
>>>> Right.
>>>> But nowhere in my script(metrites.py) i use an 'Ά' so i really have no
>>>> clue where this is coming from.
>>>>
>>>> And you are right if it was a byte came from an utf-8 encoding scheme
>>>> then it would be automatically decoded.
>>>>
>>>> The only thing i can say for use is that this problem a[[ear only
>>>> when i
>>>> cloudflare my domain "superhost.gr"
>>>>
>>>> If i un-cloudlflare it it cease to display errors.
>>>>
>>>> Can you tell me hpw to write the following properly:
>>>>
>>>> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
>>>> 'UnResolved'
>>>>
>>>> so even if the function fails "unresolved" to be returned back?
>>>> Somehow i need to capture the error.
>>>>
>>>> Or it dosnt have to do it the or operand will be returned?
>>>>
>>> If gethostbyaddr fails, it raises socket.gaierror, (which, from Python
>>> 3.3 onwards, is a subclass of OSError), so try catching that, setting
>>> 'host' to 'UnResolved' if it's raised.
>>>
>>> Also, try printing out ascii(os.environ['REMOTE_ADDR']).
>>>
>>
>> I have followed your suggestion by trying this:
>>
>> try:
>>     host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
>> except socket.gaierror:
>>     host = "UnResolved"
>>
>> and then re-cloudlflared "superhost.gr" domain
>>
>> http://superhost.gr/ gives internal server error.
>>
> Try catching OSError instead. (As I said, from Python 3.3,
> socket.gaierror is a subclass of it.)
>

At least CloudFlare doesn't give me issues:

if i try this:

try:
	host = os.environ['REMOTE_ADDR'][0]
except socket.gaierror:
	host = "UnResolved"

then i get no errors and a valid ip back

but the above fails.

I don't know how to catch the exception with OSError.

i know only this two:

except socket.gaierror:
except socket.herror

both fail.

-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#49872

FromMRAB <python@mrabarnett.plus.com>
Date2013-07-04 16:10 +0100
Message-ID<mailman.4237.1372950640.3114.python-list@python.org>
In reply to#49861
On 04/07/2013 14:38, Νίκος Γκρ33κ wrote:
> Στις 4/7/2013 4:34 μμ, ο/η MRAB έγραψε:
>> On 04/07/2013 13:47, Νίκος wrote:
>>> Στις 4/7/2013 3:07 μμ, ο/η MRAB έγραψε:
>>>> On 04/07/2013 12:36, Νίκος wrote:
>>>>> Στις 4/7/2013 2:06 μμ, ο/η MRAB έγραψε:
>>>>>> On 04/07/2013 11:38, Νίκος wrote:
>>>>>>> Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:
>>>>>>>> Am 04.07.2013 10:37, schrieb Νίκος:
>>>>>>>>> I just started to have this error without changing nothing
>>>>>>>>
>>>>>>>> Well, undo the nothing that you didn't change. ;)
>>>>>>>>
>>>>>>>>> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in
>>>>>>>>> position 0:
>>>>>>>>> invalid start byte
>>>>>>>>> [Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97]
>>>>>>>>> Premature
>>>>>>>>> end
>>>>>>>>> of script headers: metrites.py
>>>>>>>>>
>>>>>>>>> Why cant it decode the starting byte? what starting byte is that?
>>>>>>>>
>>>>>>>> It's the 0xb6 but it's expecting the starting byte of a UTF-8
>>>>>>>> sequence.
>>>>>>>> Please do some research on UTF-8, that should clear it up. You could
>>>>>>>> also search for common causes of that error.
>>>>>>>
>>>>>>> So you are also suggesting that what gesthostbyaddr() returns is not
>>>>>>> utf-8 encoded too?
>>>>>>>
>>>>>>> What character is 0xb6 anyways?
>>>>>>>
>>>>>> Well, it's from a bytestring, so you'll have to specify what encoding
>>>>>> you're using! (It clearly isn't UTF-8.)
>>>>>>
>>>>>> If it's ISO-8859-7 (what you've previously referred to as
>>>>>> "greek-iso"),
>>>>>> then:
>>>>>>
>>>>>>  >>> import unicodedata
>>>>>>  >>> unicodedata.name(b"\xb6".decode("ISO-8859-7"))
>>>>>> 'GREEK CAPITAL LETTER ALPHA WITH TONOS'
>>>>>>
>>>>>> You'll need to find out where that bytestring is coming from.
>>>>>
>>>>> Right.
>>>>> But nowhere in my script(metrites.py) i use an 'Ά' so i really have no
>>>>> clue where this is coming from.
>>>>>
>>>>> And you are right if it was a byte came from an utf-8 encoding scheme
>>>>> then it would be automatically decoded.
>>>>>
>>>>> The only thing i can say for use is that this problem a[[ear only
>>>>> when i
>>>>> cloudflare my domain "superhost.gr"
>>>>>
>>>>> If i un-cloudlflare it it cease to display errors.
>>>>>
>>>>> Can you tell me hpw to write the following properly:
>>>>>
>>>>> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
>>>>> 'UnResolved'
>>>>>
>>>>> so even if the function fails "unresolved" to be returned back?
>>>>> Somehow i need to capture the error.
>>>>>
>>>>> Or it dosnt have to do it the or operand will be returned?
>>>>>
>>>> If gethostbyaddr fails, it raises socket.gaierror, (which, from Python
>>>> 3.3 onwards, is a subclass of OSError), so try catching that, setting
>>>> 'host' to 'UnResolved' if it's raised.
>>>>
>>>> Also, try printing out ascii(os.environ['REMOTE_ADDR']).
>>>>
>>>
>>> I have followed your suggestion by trying this:
>>>
>>> try:
>>>     host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
>>> except socket.gaierror:
>>>     host = "UnResolved"
>>>
>>> and then re-cloudlflared "superhost.gr" domain
>>>
>>> http://superhost.gr/ gives internal server error.
>>>
>> Try catching OSError instead. (As I said, from Python 3.3,
>> socket.gaierror is a subclass of it.)
>>
>
> At least CloudFlare doesn't give me issues:
>
> if i try this:
>
> try:
> 	host = os.environ['REMOTE_ADDR'][0]
> except socket.gaierror:
> 	host = "UnResolved"
>
It's pointless trying to catch a socket exception here because you're
not using a socket, you're just getting a string from an environment
variable.

> then i get no errors and a valid ip back
>
> but the above fails.
>
> I don't know how to catch the exception with OSError.
>
> i know only this two:
>
> except socket.gaierror:
> except socket.herror
>
> both fail.
>
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!

[toc] | [prev] | [next] | [standalone]


#49881

FromΝίκος Γκρ33κ <nikos@superhost.gr>
Date2013-07-04 18:56 +0300
Message-ID<kr45uu$trg$1@news.grnet.gr>
In reply to#49872
Στις 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 ?

seems very general...

-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


Page 1 of 4  [1] 2 3 4  Next page →

Back to top | Article view | comp.lang.python


csiph-web