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 2 of 4 — ← Prev page 1 [2] 3 4  Next page →


#50519

FromWayne Werner <wayne@waynewerner.com>
Date2013-07-12 06:47 -0500
Message-ID<mailman.4631.1373629687.3114.python-list@python.org>
In reply to#49881

[Multipart message — attachments visible in raw view] — view raw

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

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


#50520

FromFerrous Cranus <nikos@superhost.gr>
Date2013-07-12 14:56 +0300
Message-ID<kroqsn$jt$1@news.grnet.gr>
In reply to#50519
Στις 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.
-- 
What is now proved was at first only imagined!

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


#50535

FromDave Angel <davea@davea.name>
Date2013-07-12 11:46 -0400
Message-ID<mailman.4642.1373644014.3114.python-list@python.org>
In reply to#50520
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

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


#49853

FromΝίκος <nikos@superhost.gr>
Date2013-07-04 15:52 +0300
Message-ID<kr3r7b$9h4$2@news.grnet.gr>
In reply to#49847
Στις 4/7/2013 3:07 μμ, ο/η MRAB έγραψε:
> Also, try printing out ascii(os.environ['REMOTE_ADDR']).

'108.162.229.97' is the result of:

print( ascii(os.environ['REMOTE_ADDR']) )

Seems perfectly valid. and also have a PTR record, so that leaved us 
clueless about the internal server error.
-- 
What is now proved was at first only imagined!

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


#49862

FromMRAB <python@mrabarnett.plus.com>
Date2013-07-04 14:34 +0100
Message-ID<mailman.4230.1372944866.3114.python-list@python.org>
In reply to#49853
On 04/07/2013 13:52, Νίκος wrote:
> Στις 4/7/2013 3:07 μμ, ο/η MRAB έγραψε:
>> Also, try printing out ascii(os.environ['REMOTE_ADDR']).
>
> '108.162.229.97' is the result of:
>
> print( ascii(os.environ['REMOTE_ADDR']) )
>
> Seems perfectly valid. and also have a PTR record, so that leaved us
> clueless about the internal server error.
>
For me, socket.gethostbyaddr('108.162.229.97') raises socket.herror,
which is also a subclass of OSError from Python 3.3 onwards.

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


#49870

FromΝίκος Γκρ33κ <nikos@superhost.gr>
Date2013-07-04 17:48 +0300
Message-ID<kr420b$oaj$1@news.grnet.gr>
In reply to#49862


-------- Αρχικό μήνυμα --------
Θέμα: Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in 
position 0: invalid start byte
Ημερομηνία: Thu, 04 Jul 2013 14:34:42 +0100
Από: MRAB <python@mrabarnett.plus.com>
Απάντηση: python-list@python.org
Προς: python-list@python.org
Ομάδες συζήτησης: comp.lang.python
Αναφορές: <kr3c7k$tjs$2@news.grnet.gr> 
<n3tfaa-eqh.ln1@satorlaser.homedns.org> <kr3jai$jn0$4@news.grnet.gr> 
<mailman.4219.1372935984.3114.python-list@python.org> 
<kr3mnq$jn0$6@news.grnet.gr> 
<mailman.4222.1372939645.3114.python-list@python.org> 
<kr3r7b$9h4$2@news.grnet.gr>

On 04/07/2013 13:52, Νίκος wrote:
> Στις 4/7/2013 3:07 μμ, ο/η MRAB έγραψε:
>> Also, try printing out ascii(os.environ['REMOTE_ADDR']).
>
> '108.162.229.97' is the result of:
>
> print( ascii(os.environ['REMOTE_ADDR']) )
>
> Seems perfectly valid. and also have a PTR record, so that leaved us
> clueless about the internal server error.
>
For me, socket.gethostbyaddr('108.162.229.97') raises socket.herror,
which is also a subclass of OSError from Python 3.3 onwards.

Tell me how i should write the try/except please.
-- 
What is now proved was at first only imagined!

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


#49855

FromUlrich Eckhardt <ulrich.eckhardt@dominolaser.com>
Date2013-07-04 15:07 +0200
Message-ID<vk8gaa-fki.ln1@satorlaser.homedns.org>
In reply to#49838
Am 04.07.2013 12:38, schrieb Νίκος:
> Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:
>> Am 04.07.2013 10:37, schrieb Νίκος:
>>> 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?

I never said that. And do some research yourself, you were given plenty 
of hints.

Uli

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


#49858

FromΝίκος Γκρ33κ <nikos@superhost.gr>
Date2013-07-04 16:26 +0300
Message-ID<kr3t67$9h4$3@news.grnet.gr>
In reply to#49855
Στις 4/7/2013 4:07 μμ, ο/η Ulrich Eckhardt έγραψε:
> Am 04.07.2013 12:38, schrieb Νίκος:
>> Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:
>>> Am 04.07.2013 10:37, schrieb Νίκος:
>>>> 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?
>
> I never said that. And do some research yourself, you were given plenty
> of hints.
>
> Uli
>
Yes and as you can see form my responses i have tried any suggestion so 
far and the problem still remains unresolved.

What you said implied that the string returned by the function cannot be 
decoded as utf-8.

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

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


#49898

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2013-07-04 16:08 -0400
Message-ID<mailman.4247.1372968544.3114.python-list@python.org>
In reply to#49838
On Thu, 04 Jul 2013 13:38:09 +0300, ????? <nikos@superhost.gr> declaimed
the following:

>What character is 0xb6 anyways?
>
	It depends on the encoding... In EBCDIC it's unassigned. It's a
paragraph mark in ISO-Latin-1 (ISO-8859-1). Apparently also a paragraph
mark in ISO-Latin-9 (ISO-8859-15).

	If it is valid in UTF-8, I can't find a reference. It's not a prefix
for a multi-byte character, which implies that the previous byte should
have been something in prefix or another extended byte entry...



-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

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


#49899

FromFerrous Cranus <nikos@superhost.gr>
Date2013-07-04 23:25 +0300
Message-ID<kr4lnd$89q$1@news.grnet.gr>
In reply to#49898
Στις 4/7/2013 11:08 μμ, ο/η Dennis Lee Bieber έγραψε:
> On Thu, 04 Jul 2013 13:38:09 +0300, ????? <nikos@superhost.gr> declaimed
> the following:
>
>> What character is 0xb6 anyways?
>>
> 	It depends on the encoding... In EBCDIC it's unassigned. It's a
> paragraph mark in ISO-Latin-1 (ISO-8859-1). Apparently also a paragraph
> mark in ISO-Latin-9 (ISO-8859-15).
>
> 	If it is valid in UTF-8, I can't find a reference. It's not a prefix
> for a multi-byte character, which implies that the previous byte should
> have been something in prefix or another extended byte entry...

try:
	host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
except:
	host = "Reverse DNS Failed"

Is there a way to write the above so i cna print the error return when 
it fails?

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

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


#49900

FromLele Gaifax <lele@metapensiero.it>
Date2013-07-04 22:44 +0200
Message-ID<mailman.4248.1372970656.3114.python-list@python.org>
In reply to#49899
Ferrous Cranus <nikos@superhost.gr> writes:

> try:
> 	host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
> except:
> 	host = "Reverse DNS Failed"
>
> Is there a way to write the above so i cna print the error return when
> it fails?

Try something like

try:
	host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
except Exception as e:
	host = "Reverse DNS Failed"
        print(e)

?

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele@metapensiero.it  |                 -- Fortunato Depero, 1929.

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


#49901

FromMichael Torrie <torriem@gmail.com>
Date2013-07-04 14:53 -0600
Message-ID<mailman.4249.1372971228.3114.python-list@python.org>
In reply to#49899
On 07/04/2013 02:25 PM, Ferrous Cranus wrote:
> try:
> 	host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
> except:
> 	host = "Reverse DNS Failed"
> 
> Is there a way to write the above so i cna print the error return when 
> it fails?
> 

Do you know what IP address causes the failure?  If so write a little
python program that does the socket.gethostbyaddr and run it on the
command line!  Debugging through the CGI interface sucks.

Have you been writing python tests that you can run on the command line
during your development these last weeks?

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


#49909

FromNobody <nobody@nowhere.com>
Date2013-07-05 01:06 +0100
Message-ID<pan.2013.07.05.00.06.41.617000@nowhere.com>
In reply to#49838
On Thu, 04 Jul 2013 13:38:09 +0300, Νίκος wrote:

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

The gethostbyaddr() OS function returns a byte string with no specified
encoding. Python 3 will doubtless try to decode that to a character string
using some (probably unspecified) encoding.

Names obtained from DNS should consist entirely of ASCII characters
(gethostbyname shouldn't attempt to decode internationalised names
which use IDN, it should return the raw data).

Names obtained by other means (e.g. /etc/hosts or Active Directory) could
contain anything, but if you use non-ASCII hostnames you're asking for
trouble.

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


#49925

FromFerrous Cranus <nikos@superhost.gr>
Date2013-07-05 09:07 +0300
Message-ID<kr5nqp$t82$1@news.grnet.gr>
In reply to#49909
Στις 5/7/2013 3:06 πμ, ο/η Nobody έγραψε:
> On Thu, 04 Jul 2013 13:38:09 +0300, Νίκος wrote:
>
>> So you are also suggesting that what gesthostbyaddr() returns is not
>> utf-8 encoded too?
>
> The gethostbyaddr() OS function returns a byte string with no specified
> encoding. Python 3 will doubtless try to decode that to a character string
> using some (probably unspecified) encoding.

I see, but if the function returns a byte string not inutf-8 format then 
how my script is uspposes to decode this byte string?

And why only this error happens when i cloudflare my domain, while when 
i un-cloudflare it are reverse DNS are being resolves without problem.
So the queston is: How come it only fails when i cloidflare the domain?

Also please comment on that:

host =  gethostbyaddr(....) or "UnResolved"

This will return the first argument that define the evaluation as being 
true or untrue.

if function returns false the the 2nd argument.
Nut if the function gives an exception will the condition return the 2nd 
argument or will the program fail?

I was udner the impression that i could avoid error handling  inside 
try/excepts by utilizing "or".
-- 
What is now proved was at first only imagined!

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


#49930

FromLele Gaifax <lele@metapensiero.it>
Date2013-07-05 08:55 +0200
Message-ID<mailman.4268.1373007329.3114.python-list@python.org>
In reply to#49925
Ferrous Cranus <nikos@superhost.gr> writes:

> host =  gethostbyaddr(....) or "UnResolved"
>
> This will return the first argument that define the evaluation as
> being true or untrue.
>
> if function returns false the the 2nd argument.
> Nut if the function gives an exception will the condition return the
> 2nd argument or will the program fail?
>
> I was udner the impression that i could avoid error handling  inside
> try/excepts by utilizing "or".

No, you had the wrong impression. Why don't you simply invoke the Python
interpreter and try things out with that??

    >>> a = 1/0 or 100
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ZeroDivisionError: division by zero
    >>> a
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'a' is not defined
    >>> a = 0/1 or 100
    >>> a
    100
    >>>

ciao, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele@metapensiero.it  |                 -- Fortunato Depero, 1929.

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


#49933

FromΝίκος Gr33k <nikos@superhost.gr>
Date2013-07-05 10:10 +0300
Message-ID<kr5rgm$t82$3@news.grnet.gr>
In reply to#49930
Στις 5/7/2013 9:55 πμ, ο/η Lele Gaifax έγραψε:
> Ferrous Cranus <nikos@superhost.gr> writes:
>
>> host =  gethostbyaddr(....) or "UnResolved"
>>
>> This will return the first argument that define the evaluation as
>> being true or untrue.
>>
>> if function returns false the the 2nd argument.
>> Nut if the function gives an exception will the condition return the
>> 2nd argument or will the program fail?
>>
>> I was udner the impression that i could avoid error handling  inside
>> try/excepts by utilizing "or".
>
> No, you had the wrong impression. Why don't you simply invoke the Python
> interpreter and try things out with that??
>
>      >>> a = 1/0 or 100
>      Traceback (most recent call last):
>        File "<stdin>", line 1, in <module>
>      ZeroDivisionError: division by zero
>      >>> a
>      Traceback (most recent call last):
>        File "<stdin>", line 1, in <module>
>      NameError: name 'a' is not defined
>      >>> a = 0/1 or 100
>      >>> a
>      100
>      >>>

Thank you Lele, i wanted to but i had no idea how to test it.
Your devision by zero is very smart thing to test!

So it proves that a condition cannot be evaluation as truthy or falsey 
if one of the operators is giving out an exception.
Thank you.


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

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


#49928

FromΝίκος Gr33k <nikos@superhost.gr>
Date2013-07-05 09:51 +0300
Message-ID<kr5qdh$t82$2@news.grnet.gr>
In reply to#49909
Στις 5/7/2013 3:06 πμ, ο/η Nobody έγραψε:
> On Thu, 04 Jul 2013 13:38:09 +0300, Νίκος wrote:
>
>> So you are also suggesting that what gesthostbyaddr() returns is not
>> utf-8 encoded too?
>
> The gethostbyaddr() OS function returns a byte string with no specified
> encoding. Python 3 will doubtless try to decode that to a character string
> using some (probably unspecified) encoding.
>
> Names obtained from DNS should consist entirely of ASCII characters
> (gethostbyname shouldn't attempt to decode internationalised names
> which use IDN, it should return the raw data).
>
> Names obtained by other means (e.g. /etc/hosts or Active Directory) could
> contain anything, but if you use non-ASCII hostnames you're asking for
> trouble.
>

Please help because i just happened to noticed that after having this code:

try:
	host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
except Exception as e:
	host = "Reverse DNS Failed"


all requests are being resolves, result to:


Reverse DNS Failed as you can see here:
http://superhost.gr/?show=log&page=index.html

How can the above code not be able to reeverse dns any more and it falls 
back to  the failed string?

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

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


#49932

FromLele Gaifax <lele@metapensiero.it>
Date2013-07-05 09:06 +0200
Message-ID<mailman.4270.1373007990.3114.python-list@python.org>
In reply to#49928
Νίκος Gr33k <nikos@superhost.gr> writes:

> try:
> 	host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
> except Exception as e:
> 	host = "Reverse DNS Failed"
>
> How can the above code not be able to reeverse dns any more and it
> falls back to  the failed string?

The only way to know is actually printing out the exception, either to
stderr, or better using the logging facility, as I suggested.

FYI, your code above is (almost) exactly equivalent to the simpler

    try:
    	host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
    except:
    	host = "Reverse DNS Failed"

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele@metapensiero.it  |                 -- Fortunato Depero, 1929.

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


#49934

FromΝίκος Gr33k <nikos@superhost.gr>
Date2013-07-05 10:13 +0300
Message-ID<kr5rno$7p3$1@news.grnet.gr>
In reply to#49932
Στις 5/7/2013 10:06 πμ, ο/η Lele Gaifax έγραψε:
>      try:
>      	host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
>      except:
>      	host = "Reverse DNS Failed"


Yes i uses to had it like that, until i was looking for ways to make it 
hold the error

except Exception as e:
	print( e )
	host = e

but print( e ) in the way i used to had it doesn't print out the error, 
it instead gives an internal server error on browser.

I must somehow take a look at the error to understand why every visitor 
i have gets UnResolved, but how since prints fails?

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

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


#49946

FromDave Angel <davea@davea.name>
Date2013-07-05 04:27 -0400
Message-ID<mailman.4282.1373012861.3114.python-list@python.org>
In reply to#49934
On 07/05/2013 03:13 AM, Νίκος Gr33k wrote:
> Στις 5/7/2013 10:06 πμ, ο/η Lele Gaifax έγραψε:
>>      try:
>>          host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
>>      except:
>>          host = "Reverse DNS Failed"
>
>
> Yes i uses to had it like that, until i was looking for ways to make it
> hold the error
>
> except Exception as e:
>      print( e )
>      host = e
>
> but print( e ) in the way i used to had it doesn't print out the error,
> it instead gives an internal server error on browser.
>
> I must somehow take a look at the error to understand why every visitor
> i have gets UnResolved, but how since prints fails?
>


How have you been doing it all along?  Just open a console onto that 
server, start the appropriate version of Python interactively, and try 
the things we've been talking about.  If it fails the same way as within 
the cgi environmnet, you get full visibility.

Or if the problems cannot be recreated outside the cgi environment, use 
the log files you've been logging other problems into.  Or simply open a 
text file for writing, and add a file= keyword parameter to the print 
function call.

      print(repr(e), file=myfile)



-- 
DaveA

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


Page 2 of 4 — ← Prev page 1 [2] 3 4  Next page →

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


csiph-web