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


#49954

FromΝίκος Gr33k <nikos@superhost.gr>
Date2013-07-05 12:01 +0300
Message-ID<kr620v$koa$2@news.grnet.gr>
In reply to#49946
Στις 5/7/2013 11:27 πμ, ο/η Dave Angel έγραψε:
>
> 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)

Yes you are correct, problem need to be recreated within the cgi env.

try:
	remadd = os.environ('REMOTE_ADDR')
	tuple3 = socket.gethostbyaddr(remadd)
	host = tuple3[0]
except Exception as e:
	host = repr(e)


http://superhost.gr/?show=log&page=index.html shows explicitly the same 
kind of error that python interpreter via cli gave me the same error!

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

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


#49938

FromBenjamin Kaplan <benjamin.kaplan@case.edu>
Date2013-07-05 00:21 -0700
Message-ID<mailman.4273.1373009248.3114.python-list@python.org>
In reply to#49928

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

On Jul 5, 2013 12:12 AM, "Lele Gaifax" <lele@metapensiero.it> wrote:
>
> Νίκος 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.
>

They aren't equivalent. "except Exception" won't catch KeyboardInterrupt or
SystemExit or a few others that you really don't want to catch in a generic
error handler. You should almost never have a bare except.

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


#49943

FromDave Angel <davea@davea.name>
Date2013-07-05 03:50 -0400
Message-ID<mailman.4281.1373010669.3114.python-list@python.org>
In reply to#49928
On 07/05/2013 02:51 AM, Νίκος Gr33k wrote:

     <SNIP>
>
> 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"

Don't ever catch a bare Exception class.  Make it more specific to the 
particular problem you're trying to suppress.

In particular, your previous problem with the utf-8 decoding will also 
be caught by the Exception class, so it'll get all lumped together as 
"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?
>

Since you've not made any progress with all the other suggestions, how 
about if you decompose this line into several, and see just which one is 
failing?  Maybe that'll tell you what's going on.  In general, 
suppressing an exception without knowing why it's firing is a huge mistake.

The line started as:

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

refactor that to:
        remadd = os.environ('REMOVE_ADDR')
        tuple3 = socket.gethostbyaddr(remadd)
        host = tuple3[0]

and see which one throws the exception.  Then once you have that, 
examine the exact parameters that might be triggering the problem.  In 
particular, figure out the exact types and values for remadd and tuple3.

        print(type(remadd) + " : " + repr(remadd))

Of course, print itself won't work too well in a CGI environment.  But 
you must have solved that problem by now, either using log files or 
running the program excerpt in a regular console.


-- 
DaveA

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


#49944

FromΝίκος Gr33k <nikos@superhost.gr>
Date2013-07-05 11:00 +0300
Message-ID<kr5uem$dq8$1@news.grnet.gr>
In reply to#49943
Στις 5/7/2013 10:50 πμ, ο/η Dave Angel έγραψε:
>
> The line started as:
>
>  >      host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
>
> refactor that to:
>         remadd = os.environ('REMOVE_ADDR')
>         tuple3 = socket.gethostbyaddr(remadd)
>         host = tuple3[0]
>
> and see which one throws the exception.  Then once you have that,
> examine the exact parameters that might be triggering the problem.  In
> particular, figure out the exact types and values for remadd and tuple3.
>
>         print(type(remadd) + " : " + repr(remadd))

I'am not sure how iam supposed to write this: i just tried this:


try:
	remadd = os.environ('REMOVE_ADDR')
	tuple3 = socket.gethostbyaddr(remadd)
	host = tuple3[0]
except:
	host = type(remadd) + " : " + repr(remadd)


but iam getting an internal server error.

I didnt print it as you said but its the same thing host var gets 
printed later on.

Now, why would this give an internal server error?

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

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


#49948

FromDave Angel <davea@davea.name>
Date2013-07-05 04:35 -0400
Message-ID<mailman.4283.1373013336.3114.python-list@python.org>
In reply to#49944
On 07/05/2013 04:00 AM, Νίκος Gr33k wrote:
> Στις 5/7/2013 10:50 πμ, ο/η Dave Angel έγραψε:
>>
>> The line started as:
>>
>>  >      host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
>>
>> refactor that to:
>>         remadd = os.environ('REMOVE_ADDR')
>>         tuple3 = socket.gethostbyaddr(remadd)
>>         host = tuple3[0]
>>
>> and see which one throws the exception.  Then once you have that,
>> examine the exact parameters that might be triggering the problem.  In
>> particular, figure out the exact types and values for remadd and tuple3.
>>
>>         print(type(remadd) + " : " + repr(remadd))
>
> I'am not sure how iam supposed to write this: i just tried this:
>
>
> try:
>      remadd = os.environ('REMOVE_ADDR')
>      tuple3 = socket.gethostbyaddr(remadd)
>      host = tuple3[0]
> except:
>      host = type(remadd) + " : " + repr(remadd)
>
>
> but iam getting an internal server error.
>
> I didnt print it as you said but its the same thing host var gets
> printed later on.
>
> Now, why would this give an internal server error?
>

I have no idea what causes an internal server error.  It's up to you to 
get the output of the expression to some location you can examine. 
Easiest way is to run those 3 lines directly on the server, not in the 
cgi environment.

But if you don't have any debugging tools, then STOP right now and build 
some.  Use logging, or redirect print, or do something that the server 
folks provide as debugging aids.  But just blindly guessing is 
ludicrous.  So also is throwing out clues by using a bare except.

Assigning that string to host makes no sense at all.  And neither does 
putting it in the except clause.  You want to get that string to YOUR 
eyes, not to the server who might get an internal server error.


-- 
DaveA

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


#49952

FromΝίκος Gr33k <nikos@superhost.gr>
Date2013-07-05 11:49 +0300
Message-ID<kr61as$koa$1@news.grnet.gr>
In reply to#49948
Στις 5/7/2013 11:35 πμ, ο/η Dave Angel έγραψε:
> On 07/05/2013 04:00 AM, Νίκος Gr33k wrote:
>> Στις 5/7/2013 10:50 πμ, ο/η Dave Angel έγραψε:
>>>
>>> The line started as:
>>>
>>>  >      host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
>>>
>>> refactor that to:
>>>         remadd = os.environ('REMOVE_ADDR')
>>>         tuple3 = socket.gethostbyaddr(remadd)
>>>         host = tuple3[0]
>>>
>>> and see which one throws the exception.  Then once you have that,
>>> examine the exact parameters that might be triggering the problem.  In
>>> particular, figure out the exact types and values for remadd and tuple3.
>>>
>>>         print(type(remadd) + " : " + repr(remadd))
>>
>> I'am not sure how iam supposed to write this: i just tried this:
>>
>>
>> try:
>>      remadd = os.environ('REMOVE_ADDR')
>>      tuple3 = socket.gethostbyaddr(remadd)
>>      host = tuple3[0]
>> except:
>>      host = type(remadd) + " : " + repr(remadd)
>>
>>
>> but iam getting an internal server error.
>>
>> I didnt print it as you said but its the same thing host var gets
>> printed later on.
>>
>> Now, why would this give an internal server error?
>>
>
> I have no idea what causes an internal server error.  It's up to you to
> get the output of the expression to some location you can examine.
> Easiest way is to run those 3 lines directly on the server, not in the
> cgi environment.
>
> But if you don't have any debugging tools, then STOP right now and build
> some.  Use logging, or redirect print, or do something that the server
> folks provide as debugging aids.  But just blindly guessing is
> ludicrous.  So also is throwing out clues by using a bare except.
>
> Assigning that string to host makes no sense at all.  And neither does
> putting it in the except clause.  You want to get that string to YOUR
> eyes, not to the server who might get an internal server error.

I don't think running it via 'cli' would help much, since its a 
cgi-script and ip addr function have no meaning calling them in plain 
our of a cgi environment but here it is:


Python 3.3.2 (default, Jun  3 2013, 16:18:05)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
 >>> import os
 >>> remadd = os.environ('REMOVE_ADDR')
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: '_Environ' object is not callable



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

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


#49955

FromDave Angel <davea@davea.name>
Date2013-07-05 05:21 -0400
Message-ID<mailman.4285.1373016111.3114.python-list@python.org>
In reply to#49952
On 07/05/2013 04:49 AM, Νίκος Gr33k wrote:
>
      <SNIP>

> I don't think running it via 'cli' would help much, since its a
> cgi-script and ip addr function have no meaning calling them in plain
> our of a cgi environment but here it is:
>

No idea how to parse "have no meaning calling them in plain our of a cgi 
environment"


>
> Python 3.3.2 (default, Jun  3 2013, 16:18:05)
> [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> import os
>  >>> remadd = os.environ('REMOVE_ADDR')
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> TypeError: '_Environ' object is not callable
>
But there were two problems with the code you faithfully copied from my 
earlier post.  One was already pointed out by feedthetroll, that I 
accidentally changed REMOTE_ADDR to REMOVE_ADDR.

The other one is perhaps more subtle; I replaced square brackets with 
parentheses.

So try again with:

  >>> import os
  >>> remadd = os.environ['REMOTE_ADDR']

I get an error:

Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/usr/local/lib/python3.3/os.py", line 669, in __getitem__
     value = self._data[self.encodekey(key)]
KeyError: b'REMOTE_ADDR'


but presumably your machine actually has such an environment variable.

Isn't that mistake something  you could easily have caught?  Or were you 
just blindly pasting my bugs without understanding what I was trying to 
do with refactoring?

Anyway, I can't see any reason why the rest of the sequence shouldn't 
behave identically from a terminal as it does in CGI.


-- 
DaveA

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


#49956

FromΝίκος Gr33k <nikos@superhost.gr>
Date2013-07-05 12:25 +0300
Message-ID<kr63ea$koa$3@news.grnet.gr>
In reply to#49955
Στις 5/7/2013 12:21 μμ, ο/η Dave Angel έγραψε:
> On 07/05/2013 04:49 AM, Νίκος Gr33k wrote:
>>
>       <SNIP>
>
>> I don't think running it via 'cli' would help much, since its a
>> cgi-script and ip addr function have no meaning calling them in plain
>> our of a cgi environment but here it is:
>>
>
> No idea how to parse "have no meaning calling them in plain our of a cgi
> environment"
>
>
>>
>> Python 3.3.2 (default, Jun  3 2013, 16:18:05)
>> [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
>> Type "help", "copyright", "credits" or "license" for more information.
>>  >>> import os
>>  >>> remadd = os.environ('REMOVE_ADDR')
>> Traceback (most recent call last):
>>    File "<stdin>", line 1, in <module>
>> TypeError: '_Environ' object is not callable
>>
> But there were two problems with the code you faithfully copied from my
> earlier post.  One was already pointed out by feedthetroll, that I
> accidentally changed REMOTE_ADDR to REMOVE_ADDR.
>
> The other one is perhaps more subtle; I replaced square brackets with
> parentheses.
>
> So try again with:
>
>   >>> import os
>   >>> remadd = os.environ['REMOTE_ADDR']
>
> I get an error:
>
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
>    File "/usr/local/lib/python3.3/os.py", line 669, in __getitem__
>      value = self._data[self.encodekey(key)]
> KeyError: b'REMOTE_ADDR'
>
>
> but presumably your machine actually has such an environment variable.
>
> Isn't that mistake something  you could easily have caught?  Or were you
> just blindly pasting my bugs without understanding what I was trying to
> do with refactoring?
>
> Anyway, I can't see any reason why the rest of the sequence shouldn't
> behave identically from a terminal as it does in CGI.

Yes i didnt see your typo and i have corrected it:


try:
	remadd = os.environ('REMOTE_ADDR')
	tuple3 = socket.gethostbyaddr(remadd)
	host = tuple3[0]
except Exception as e:
	host = repr(e)


Ima still receiving the same kind of erro as i did with cli as well.

You can view the error in the very first line here:

http://superhost.gr/?show=log&page=index.html


which yields: TypeError("'_Environ' object is not callable",)


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

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


#49962

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

> You can view the error in the very first line here:
>
> http://superhost.gr/?show=log&page=index.html

No, visiting that page simply emit the standard Apache error page,
without details.

>
> which yields: TypeError("'_Environ' object is not callable",)

Dave already told you the reason[1]. Νίκος, *read* **and** *understand*
our *whole* answers to your questions, otherwise we are wasting time,
you, and us!

ciao, lele.

[1] “… The other one is perhaps more subtle; I replaced square brackets
     with parentheses.”
-- 
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]


#49964

FromΝίκος Gr33k <nikos@superhost.gr>
Date2013-07-05 13:28 +0300
Message-ID<kr6750$424$1@news.grnet.gr>
In reply to#49962
Στις 5/7/2013 1:24 μμ, ο/η Lele Gaifax έγραψε:
> Νίκος Gr33k <nikos@superhost.gr> writes:
>
>> You can view the error in the very first line here:
>>
>> http://superhost.gr/?show=log&page=index.html
>
> No, visiting that page simply emit the standard Apache error page,
> without details.
>
>>
>> which yields: TypeError("'_Environ' object is not callable",)
>
> Dave already told you the reason[1]. Νίκος, *read* **and** *understand*
> our *whole* answers to your questions, otherwise we are wasting time,
> you, and us!
>
> ciao, lele.
>
> [1] “… The other one is perhaps more subtle; I replaced square brackets
>       with parentheses.”
>

I read carefully all of tour answer please try to load again:

http://superhost.gr/?show=log&page=index.html

Di i miss an explanation on this?

TypeError("'_Environ' object is not callable",)

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

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


#49963

FromΝίκος Gr33k <nikos@superhost.gr>
Date2013-07-05 13:26 +0300
Message-ID<kr671h$3cb$1@news.grnet.gr>
In reply to#49956
Στις 5/7/2013 12:25 μμ, ο/η Νίκος Gr33k έγραψε:
>
> try:
>      remadd = os.environ('REMOTE_ADDR')
>      tuple3 = socket.gethostbyaddr(remadd)
>      host = tuple3[0]
> except Exception as e:
>      host = repr(e)

> which yields: TypeError("'_Environ' object is not callable",)

Any thoufgs as to why os.environ('REMOTE_ADDR') gives the above error?

I noticed that if i remove my domain from cloudflare the gethostbyaddr 
as it uses too months now.
-- 
What is now proved was at first only imagined!

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


#49966

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

> Στις 5/7/2013 12:25 μμ, ο/η Νίκος Gr33k έγραψε:
>>
>> try:
>>      remadd = os.environ('REMOTE_ADDR')
>>      tuple3 = socket.gethostbyaddr(remadd)
>>      host = tuple3[0]
>> except Exception as e:
>>      host = repr(e)
>
>> which yields: TypeError("'_Environ' object is not callable",)
>
> Any thoufgs as to why os.environ('REMOTE_ADDR') gives the above error?

Yes, I'd try to understand the error message, and eventually lookup the
documentation on os.environ to see what type of object it is bound
to. The solution should be easy.

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]


#49967

FromΝίκος Gr33k <nikos@superhost.gr>
Date2013-07-05 13:42 +0300
Message-ID<kr67uu$424$3@news.grnet.gr>
In reply to#49966
Στις 5/7/2013 1:36 μμ, ο/η Lele Gaifax έγραψε:
> Νίκος Gr33k <nikos@superhost.gr> writes:
>
>> Στις 5/7/2013 12:25 μμ, ο/η Νίκος Gr33k έγραψε:
>>>
>>> try:
>>>       remadd = os.environ('REMOTE_ADDR')
>>>       tuple3 = socket.gethostbyaddr(remadd)
>>>       host = tuple3[0]
>>> except Exception as e:
>>>       host = repr(e)
>>
>>> which yields: TypeError("'_Environ' object is not callable",)
>>
>> Any thoufgs as to why os.environ('REMOTE_ADDR') gives the above error?
>
> Yes, I'd try to understand the error message, and eventually lookup the
> documentation on os.environ to see what type of object it is bound
> to. The solution should be easy.

Looks now when i print( repr(e)) i get

UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3

but what string does it try to decode and jeeps failing?


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

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


#49969

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

> Looks now when i print( repr(e)) i get
>
> UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3
>
> but what string does it try to decode and jeeps failing?

Reasonably it's the second one, as the first clearly seems the tag of
the decoder that tried to translate it to Unicode.

As already explained, your immediate goal should be trying to understand
from *where* that byte string is coming. I can't help on that, sorry.

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]


#49970

FromΝίκος Gr33k <nikos@superhost.gr>
Date2013-07-05 14:05 +0300
Message-ID<kr6994$8hc$1@news.grnet.gr>
In reply to#49969
Στις 5/7/2013 1:59 μμ, ο/η Lele Gaifax έγραψε:
> Νίκος Gr33k <nikos@superhost.gr> writes:
>
>> Looks now when i print( repr(e)) i get
>>
>> UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3
>>
>> but what string does it try to decode and jeeps failing?
>
> Reasonably it's the second one, as the first clearly seems the tag of
> the decoder that tried to translate it to Unicode.

2nd one of what? 2nd byte in order?
Can ou show me form which characters does this string consist of so we 
migth have an idea of where its coming from if we know what it looks like?

> As already explained, your immediate goal should be trying to understand
> from *where* that byte string is coming. I can't help on that, sorry.

Thats what i'm trying to do.
If i completely remove the gethostbyaddr fucntion adds function then 
there is nor problem.

The problem is recreating when the script tries to decode a hostname.

For some bizarre reason if i exclude my domain from CloudFlare then the 
reverse DNS resolution of the visitors hostname would be returned properly.

I will do it right now for you to see.
-- 
What is now proved was at first only imagined!

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


#49971

FromΝίκος Gr33k <nikos@superhost.gr>
Date2013-07-05 14:16 +0300
Message-ID<kr69ub$avt$1@news.grnet.gr>
In reply to#49970
Στις 5/7/2013 2:05 μμ, ο/η Νίκος Gr33k έγραψε:
> Thats what i'm trying to do.
> If i completely remove the gethostbyaddr fucntion adds function then
> there is nor problem.
>
> The problem is recreating when the script tries to decode a hostname.
>
> For some bizarre reason if i exclude my domain from CloudFlare then the
> reverse DNS resolution of the visitors hostname would be returned properly.
>
> I will do it right now for you to see.


Precisely as i have said it would happen:

I removed the domain form CloudFlare and your domains visting my website 
appearing as usual.

Its only when i cloudflare it and the UnicodeError happens.

But why?!?! I see no reason as to why when my domain becomes Cloudflared 
the gethostbyaddr() fails.

What kind of weird strings does it return back?


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

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


#49972

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

> Στις 5/7/2013 1:59 μμ, ο/η Lele Gaifax έγραψε:
>> Νίκος Gr33k <nikos@superhost.gr> writes:
>>
>>> UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3
>>>
>>> but what string does it try to decode and jeeps failing?
>>
>> Reasonably it's the second one, as the first clearly seems the tag of
>> the decoder that tried to translate it to Unicode.
>
> 2nd one of what? 2nd byte in order?

You asked “what string” (although you probably meant “which string”):

UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3

first string-------^^^^^^^
second string---------------^^^^^^^^^^^^^^^^^^^^^^

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]


#49973

FromΝίκος Gr33k <nikos@superhost.gr>
Date2013-07-05 14:27 +0300
Message-ID<kr6aiv$bim$1@news.grnet.gr>
In reply to#49972
Στις 5/7/2013 2:16 μμ, ο/η Lele Gaifax έγραψε:
> UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3
>
> first string-------^^^^^^^
> second string---------------^^^^^^^^^^^^^^^^^^^^^^


Hold on please!

 From where do these dashes and carets characters come from?
Also from where do you see 2 strings?

Looking at that: UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3

ic an understandn onlt that utf-8 has failsed decoding some byte stream 
satrting with \xb6

I totally not follow...
-- 
What is now proved was at first only imagined!

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


#49976

Fromfeedthetroll@gmx.de
Date2013-07-05 05:06 -0700
Message-ID<4e735bb4-bb5c-4f46-8b77-8fd0524c84f0@googlegroups.com>
In reply to#49973
Am Freitag, 5. Juli 2013 13:27:25 UTC+2 schrieb Νίκος Gr33k:
> Στις 5/7/2013 2:16 μμ, ο/η Lele Gaifax έγραψε:
>> UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3
>> first string-------^^^^^^^
>> second string---------------^^^^^^^^^^^^^^^^^^^^^^
> 
> Hold on please!
>  From where do these dashes and carets characters come from?

ROTFL!!!!
Nikos, you made my day, again! Fun is back in these threads!

> 
> Also from where do you see 2 strings?

Look, my little dumb baby: The dashes and carets point to the strings.
The first one being 'utf-8', the second one starting with '\xb6\xe3\xed' (being a bytestring, therefore the b before the ')
Sorry, I forgot. You are not using python for your business, therefore you can't know, that strings in python can for example be identified by surrounding '.

> ic an understandn onlt that utf-8 has failsed decoding some byte stream 
> satrting with \xb6
So ... where did you call utf-8() so that it could try to decode something?

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


#49965

FromΝίκος Gr33k <nikos@superhost.gr>
Date2013-07-05 13:33 +0300
Message-ID<kr67d3$424$2@news.grnet.gr>
In reply to#49955
Στις 5/7/2013 12:21 μμ, ο/η Dave Angel έγραψε:
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
>    File "/usr/local/lib/python3.3/os.py", line 669, in __getitem__
>      value = self._data[self.encodekey(key)]
> KeyError: b'REMOTE_ADDR


Wait!
Are you saying that the ip address is being returned as a byte string 
which then i have to decode with something like:

host = socket.gethostbyaddr( os.environ['REMOTE_HOST'].decode('utf-8') )[0]

?

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

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


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

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


csiph-web