Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43230 > unrolled thread
| Started by | Νίκος Γκρ33κ <nikos.gr33k@gmail.com> |
|---|---|
| First post | 2013-04-09 14:10 -0700 |
| Last post | 2013-04-16 23:56 -0700 |
| Articles | 20 on this page of 81 — 17 participants |
Back to article view | Back to comp.lang.python
Unicode issue with Python v3.3 Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-04-09 14:10 -0700
Re: Unicode issue with Python v3.3 Ian Kelly <ian.g.kelly@gmail.com> - 2013-04-09 15:34 -0600
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-09 20:16 -0700
Re: Unicode issue with Python v3.3 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-10 04:25 +0000
Re: Unicode issue with Python v3.3 Chris Angelico <rosuav@gmail.com> - 2013-04-10 14:46 +1000
Re: Unicode issue with Python v3.3 rusi <rustompmody@gmail.com> - 2013-04-09 22:06 -0700
Re: Unicode issue with Python v3.3 rusi <rustompmody@gmail.com> - 2013-04-09 23:04 -0700
Re: Unicode issue with Python v3.3 Antoine Pitrou <solipsis@pitrou.net> - 2013-04-10 07:04 +0000
Re: Unicode issue with Python v3.3 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-10 08:28 +0000
People in the python community [was Re: Unicode issue with Python v3.3] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-10 08:34 +0000
Re: People in the python community [was Re: Unicode issue with Python v3.3] Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-04-10 10:31 +0100
Re: People in the python community [was Re: Unicode issue with Python v3.3] Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-04-10 03:50 -0700
Re: People in the python community [was Re: Unicode issue with Python v3.3] Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-04-10 03:50 -0700
Re: People in the python community [was Re: Unicode issue with Python v3.3] Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-04-10 03:53 -0700
Re: People in the python community [was Re: Unicode issue with Python v3.3] Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-04-10 03:53 -0700
Re: People in the python community [was Re: Unicode issue with Python v3.3] Peter Otten <__peter__@web.de> - 2013-04-10 13:11 +0200
Re: People in the python community [was Re: Unicode issue with Python v3.3] Peter Otten <__peter__@web.de> - 2013-04-10 13:13 +0200
Re: People in the python community [was Re: Unicode issue with Python v3.3] Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-04-10 07:43 -0700
Re: People in the python community [was Re: Unicode issue with Python v3.3] Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-04-10 16:15 +0100
Re: People in the python community [was Re: Unicode issue with Python v3.3] Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-04-10 09:50 -0700
Re: People in the python community [was Re: Unicode issue with Python v3.3] Michael Torrie <torriem@gmail.com> - 2013-04-11 21:20 -0600
Re: People in the python community [was Re: Unicode issue with Python v3.3] Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-04-10 09:50 -0700
Re: People in the python community [was Re: Unicode issue with Python v3.3] Chris Angelico <rosuav@gmail.com> - 2013-04-11 01:19 +1000
Re: People in the python community [was Re: Unicode issue with Python v3.3] Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-04-10 07:43 -0700
Re: Unicode issue with Python v3.3 Arnaud Delobelle <arnodel@gmail.com> - 2013-04-10 23:56 +0100
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-10 00:23 -0700
Re: Unicode issue with Python v3.3 Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-04-10 01:06 -0700
Re: Unicode issue with Python v3.3 Cameron Simpson <cs@zip.com.au> - 2013-04-11 09:17 +1000
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-10 21:50 -0700
Re: Unicode issue with Python v3.3 Cameron Simpson <cs@zip.com.au> - 2013-04-11 20:45 +1000
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-11 03:54 -0700
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-11 03:54 -0700
Re: Unicode issue with Python v3.3 Nikos <nagia.retsina@gmail.com> - 2013-04-11 09:55 -0700
Re: Unicode issue with Python v3.3 Cameron Simpson <cs@zip.com.au> - 2013-04-13 11:41 +1000
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-12 21:50 -0700
Re: Unicode issue with Python v3.3 Cameron Simpson <cs@zip.com.au> - 2013-04-13 20:28 +1000
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-13 07:16 -0700
Re: Unicode issue with Python v3.3 Chris Angelico <rosuav@gmail.com> - 2013-04-14 01:45 +1000
Re: Unicode issue with Python v3.3 Cameron Simpson <cs@zip.com.au> - 2013-04-14 10:01 +1000
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-13 07:16 -0700
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-12 21:50 -0700
Re: Unicode issue with Python v3.3 Nikos <nagia.retsina@gmail.com> - 2013-04-11 09:55 -0700
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-10 21:50 -0700
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-11 00:13 -0700
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-11 00:13 -0700
Re: Unicode issue with Python v3.3 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-11 07:50 +0000
Re: Unicode issue with Python v3.3 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-11 08:20 +0000
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-11 03:07 -0700
Re: Unicode issue with Python v3.3 Lele Gaifax <lele@metapensiero.it> - 2013-04-11 12:45 +0200
Re: Unicode issue with Python v3.3 Nobody <nobody@nowhere.com> - 2013-04-10 19:08 +0100
Re: Unicode issue with Python v3.3 Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-04-10 11:25 -0700
Re: Unicode issue with Python v3.3 Ian Kelly <ian.g.kelly@gmail.com> - 2013-04-10 13:50 -0600
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-09 20:16 -0700
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-11 21:36 -0700
Re: Unicode issue with Python v3.3 alex23 <wuwei23@gmail.com> - 2013-04-11 22:06 -0700
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-11 22:42 -0700
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-12 05:50 -0700
Re: Unicode issue with Python v3.3 Chris Angelico <rosuav@gmail.com> - 2013-04-12 23:14 +1000
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-12 06:18 -0700
Re: Unicode issue with Python v3.3 Chris Angelico <rosuav@gmail.com> - 2013-04-12 23:21 +1000
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-12 06:18 -0700
Re: Unicode issue with Python v3.3 rusi <rustompmody@gmail.com> - 2013-04-12 06:29 -0700
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-12 07:36 -0700
Re: Unicode issue with Python v3.3 Ian Kelly <ian.g.kelly@gmail.com> - 2013-04-12 12:37 -0600
Re: Unicode issue with Python v3.3 Roy Smith <roy@panix.com> - 2013-04-12 14:49 -0400
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-12 13:48 -0700
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-12 13:48 -0700
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-13 23:00 -0700
Re: Unicode issue with Python v3.3 Cameron Simpson <cs@zip.com.au> - 2013-04-14 19:28 +1000
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-14 04:22 -0700
Re: Unicode issue with Python v3.3 Cameron Simpson <cs@zip.com.au> - 2013-04-18 09:00 +1000
Re: Unicode issue with Python v3.3 Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-04-17 20:37 -0700
Re: Unicode issue with Python v3.3 Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-04-17 20:37 -0700
Re: Unicode issue with Python v3.3 Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-04-19 12:16 -0700
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-14 04:22 -0700
Re: Unicode issue with Python v3.3 Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-04-15 11:42 -0700
Re: Unicode issue with Python v3.3 Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-04-15 11:42 -0700
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-16 23:56 -0700
Re: Unicode issue with Python v3.3 Chris Angelico <rosuav@gmail.com> - 2013-04-17 17:01 +1000
Re: Unicode issue with Python v3.3 Chris Angelico <rosuav@gmail.com> - 2013-04-17 17:32 +1000
Re: Unicode issue with Python v3.3 nagia.retsina@gmail.com - 2013-04-16 23:56 -0700
Page 3 of 5 — ← Prev page 1 2 [3] 4 5 Next page →
| From | nagia.retsina@gmail.com |
|---|---|
| Date | 2013-04-12 21:50 -0700 |
| Message-ID | <mailman.545.1365828648.3114.python-list@python.org> |
| In reply to | #43495 |
Τη Σάββατο, 13 Απριλίου 2013 4:41:57 π.μ. UTC+3, ο χρήστης Cameron Simpson έγραψε:
> On 11Apr2013 09:55, Nikos <nagia.retsina@gmail.com> wrote:
>
> | Τη Πέμπτη, 11 Απριλίου 2013 1:45:22 μ.μ. UTC+3, ο χρήστης Cameron Simpson έγραψε:
>
> | > On 10Apr2013 21:50, nagia.retsina@gmail.com <nagia.retsina@gmail.com> wrote:
>
> | > | the doctype is coming form the attempt of script metrites.py to open and read the 'index.html' file.
>
> | > | But i don't know how to try to open it as a byte file instead of an tetxt file.
>
>
>
> Lele Gaifax showed one way:
>
>
>
> from codecs import open
>
> with open('index.html', encoding='utf-8') as f:
>
> content = f.read()
>
>
>
> But a plain open() should also do:
>
>
>
> with open('index.html') as f:
>
> content = f.read()
>
>
>
> if you're not taking tight control of the file encoding.
>
>
>
> The point here is to get _text_ (i.e. str) data from the file, not bytes.
>
>
>
> If the text turns out to be incorrectly decoded (i.e. incorrectly
>
> reading the file bytes and assembling them into text strings) because
>
> the default encoding is wrong, then you may need to read for Lele's
>
> more verbose open() example to select the correct encoding.
>
>
>
> But first ignore that and get text (str) instead of bytes.
>
> If you're already getting text from the file, something later is
>
> making bytes and handing it to print().
>
>
>
> Another approach to try is to use
>
> sys.stdout.write()
>
> instead of
>
> print()
>
>
>
> The print() function will take _anything_ and write text of some form.
>
> The write() function will throw an exception if it gets the wrong type of data.
>
>
>
> If sys.stdout is opened in binary mode then write() will require
>
> bytes as data; strings will need to be explicitly turned into bytes
>
> via .encode() in order to not raise an exception.
>
>
>
> If sys.stdout is open in text mode, write() will require str data.
>
> The sys.stdout file itself will transcribe to bytes for you.
>
>
>
> If you take that route, at least you will not have confusion about
>
> str versus bytes.
>
>
>
> For an HTML output page I would advocate arranging that sys.stdout
>
> is in text mode; that way you can do the natural thing and .write()
>
> str data and lovely UTF-8 bytes will come out the other end.
>
>
>
> If the above test (using .write() instead of print()) shows it to
>
> be in binary mode we can fix that. But you need to find out.
>
>
>
> You will want access to the error messages from the CGI environment;
>
> do you have access to the web servers error_log? You can tail that
>
> in a terminal while you reload the page to see what's going on.
>
>
>
> | This works in the shell, but doesn't work on my website:
>
> |
>
> | $ cat utf8.txt
>
> | υλικό!Πρόκειται γ
>
>
>
> Ok, so your terminal is using UTF-8 as its output coding. (And so
>
> is your mail posting program, since we see it unmangled on my screen
>
> here.)
>
>
>
> | $ python3
>
> | Python 3.2.3 (default, Oct 19 2012, 20:10:41)
>
> | [GCC 4.6.3] on linux2
>
> | Type "help", "copyright", "credits" or "license" for more information.
>
> | >>> data = open('utf8.txt').read()
>
> | >>> print(data)
>
> | υλικό!Πρόκειται γ
>
>
>
> Likewise.
>
>
>
> However, in an exciting twist, I seem to recall that Python invoked
>
> interactively with aterminal as output will have the default terminal
>
> encoding in place on sys.stdout. Producing what you expect. _However_,
>
> python invoked in a batch environment where stdout is not a terminal
>
> (such as in the CGI environment producing your web page), that is
>
> _not_ necessarily the case.
>
>
>
> | >>> print(data.encode('utf-8'))
>
> | b'\xcf\x85\xce\xbb\xce\xb9\xce\xba\xcf\x8c!\xce\xa0\xcf\x81\xcf\x8c\xce\xba\xce\xb5\xce\xb9\xcf\x84\xce\xb1\xce\xb9 \xce\xb3\n'
>
> |
>
> | See, the last line is what i'am getting on my website.
>
>
>
> The above line takes your Unicode text in "data" and transcribed
>
> it to bytes using UTF-8 as the encoding. And print() is then receiving
>
> that bytes object and printing its str() representation as "b'....'".
>
> That str is itself unicode, and when print passes it to sys.stdout,
>
> _that_ transcribed the unicode "b'...'" string as bytes to your
>
> terminal. Using UTF-8 based on the previous examples above, but
>
> since all those characters are in the bottom 127 code range the
>
> byte sequence will be the same if it uses ASCII or ISO8859-1 or
>
> almost anything else:-)
>
>
>
> As you can see, there's a lot of encoding/decoding going on behind
>
> the scenes even in this superficially simple example.
>
>
>
> | If i remove
>
> | the encode('utf-8') part in metrites.py, the webpage will not show
>
> | anything at all...
>
>
>
> Ah, but data will be being output. The print() function _will_ be
>
> writing "data" out in some form. I suggest you remove the .encode()
>
> and then examine the _source_ text of the web page, not its visible
>
> form.
>
>
>
> So: remove .encode(), reload the web page, "view page source"
>
> (depends on your browser, it is ctrl-U in Firefox ((Cmd-U in firefox
>
> on a Mac))).
>
>
>
> I think a lot of the issue you have in this thread is that your
>
> page is too complex. Make another page to do the same thing, and
>
> start with nothing. Add stuff to it a single item at a time until
>
> the page behaves incorrectly. Then you will know the exact item of
>
> code that introduced the issue. And then that single item can be
>
> examined in detail for the decode/encode issues.
>
>
>
> The other issue in the thread is that people losing patience get
>
> snarky. Respond only to the technical content. If a message is only
>
> snarky, _ignore_ it. People like the last word; let them have it
>
> and you won't get sidetracked into arguments.
>
>
>
> Cheers,
>
> --
>
> Cameron Simpson <cs@zip.com.au>
>
>
>
> PCs are like a submarine, it will work fine till you open Windows. - zollie101
First of all thank you very much Cameron for your detailed help and effort to write to me:
It seems another issue had happened without my knowledge, i was uploading stuff at /root/public_html/cgi-bin instead of /home/nikos/public_html/cgi-bin.
I realized that when i deliberately made error to metrites.py scropt and i got still the same page.
Ookey after that is corrected, i then tried the plain solution and i got this response back form the shell:
Traceback (most recent call last):
File "metrites.py", line 213, in <module>
htmldata = f.read()
File "/root/.local/lib/python2.7/lib/python3.3/encodings/iso8859_7.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0xae in position 47: character maps to <undefined>
then i switched to:
with open('/home/nikos/www/' + page, encoding='utf-8') as f:
htmldata = f.read()
and i got no error at all, just pure run *from the shell*!
But i get internal server error when i try to run the webpage from the browser(Chrome).
So, can you tell me please where can i find the apache error log so to display here please?
Apcher error_log is always better than running 'python3 metrites.py' because even if the python script has no error apache will also display more web related things?
Thank you Cameron.
[toc] | [prev] | [next] | [standalone]
| From | Nikos <nagia.retsina@gmail.com> |
|---|---|
| Date | 2013-04-11 09:55 -0700 |
| Message-ID | <mailman.487.1365699327.3114.python-list@python.org> |
| In reply to | #43348 |
Τη Πέμπτη, 11 Απριλίου 2013 1:45:22 μ.μ. UTC+3, ο χρήστης Cameron Simpson έγραψε:
> On 10Apr2013 21:50, nagia.retsina@gmail.com <nagia.retsina@gmail.com> wrote:
>
> | Firtly thank uou for taking a look into the code.
>
> | the doctype is coming form the attempt of script metrites.py to open and read the 'index.html' file.
>
> | But i don't know how to try to open it as a byte file instead of an tetxt file.
>
>
>
> I think you've got it backwards. It looks like metrites.py has
>
> opened the file as bytes instead of as text (probably utf8, but
>
> that remains to be seen). Because it has opened it in binary mode
>
> you're getting bytes when you read from the file.
>
>
>
> Can you show the relevant code that opens the files and reads from
>
> it, and the print statement that is putting it back out?
>
>
>
> You probably need to ensure that metrites.py is opening it as text,
>
> with the correct encoding. Note that the encoding is nothing to
>
> do with your _output_. It is the encoding of the data in the file
>
> you are reading, and that is dictated by the editor used to make
>
> the file.
>
> Webhost && Weblog
This works in the shell, but doesn't work on my website:
$ cat utf8.txt
υλικό!Πρόκειται γ
$ python3
Python 3.2.3 (default, Oct 19 2012, 20:10:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> data = open('utf8.txt').read()
>>> print(data)
υλικό!Πρόκειται γ
>>> print(data.encode('utf-8'))
b'\xcf\x85\xce\xbb\xce\xb9\xce\xba\xcf\x8c!\xce\xa0\xcf\x81\xcf\x8c\xce\xba\xce\xb5\xce\xb9\xcf\x84\xce\xb1\xce\xb9 \xce\xb3\n'
See, the last line is what i'am getting on my website. If i remove the encode('utf-8') part in metrites.py, the webpage will not show anything at all...
[toc] | [prev] | [next] | [standalone]
| From | nagia.retsina@gmail.com |
|---|---|
| Date | 2013-04-10 21:50 -0700 |
| Message-ID | <mailman.438.1365655810.3114.python-list@python.org> |
| In reply to | #43302 |
Firtly thank uou for taking a look into the code. the doctype is coming form the attempt of script metrites.py to open and read the 'index.html' file. But i don't know how to try to open it as a byte file instead of an tetxt file.
[toc] | [prev] | [next] | [standalone]
| From | nagia.retsina@gmail.com |
|---|---|
| Date | 2013-04-11 00:13 -0700 |
| Message-ID | <b8ad1f7a-05af-4d64-ba00-fe6b42e49f27@googlegroups.com> |
| In reply to | #43315 |
Since now we k ow the problem maybe we can tell metrites.py to open index.html using utf-8 encoding rather as binary, dont you think?
[toc] | [prev] | [next] | [standalone]
| From | nagia.retsina@gmail.com |
|---|---|
| Date | 2013-04-11 00:13 -0700 |
| Message-ID | <mailman.444.1365664909.3114.python-list@python.org> |
| In reply to | #43315 |
Since now we k ow the problem maybe we can tell metrites.py to open index.html using utf-8 encoding rather as binary, dont you think?
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-04-11 07:50 +0000 |
| Message-ID | <51666b3b$0$29977$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #43330 |
On Thu, 11 Apr 2013 00:13:46 -0700, nagia.retsina wrote: > Since now we k ow the problem maybe we can tell metrites.py to open > index.html using utf-8 encoding rather as binary, dont you think? What makes you think it is UTF-8? Last time you tried decoding content as UTF-8, you got an error that it wasn't a legal UTF-8 file. Where does index.html come from? Whatever program generates that, you need to find out what encoding it is using. -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-04-11 08:20 +0000 |
| Message-ID | <5166725f$0$29977$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #43335 |
On Thu, 11 Apr 2013 07:50:19 +0000, Steven D'Aprano wrote: > On Thu, 11 Apr 2013 00:13:46 -0700, nagia.retsina wrote: > >> Since now we k ow the problem maybe we can tell metrites.py to open >> index.html using utf-8 encoding rather as binary, dont you think? > > What makes you think it is UTF-8? > > Last time you tried decoding content as UTF-8, you got an error that it > wasn't a legal UTF-8 file. Oops, sorry, correction. It wasn't a legal UTF-8 string. It was an environment variable that was causing the decoding error, since it contained illegal bytes for a UTF-8 string. > Where does index.html come from? Whatever program generates that, you > need to find out what encoding it is using. -- Steven
[toc] | [prev] | [next] | [standalone]
| From | nagia.retsina@gmail.com |
|---|---|
| Date | 2013-04-11 03:07 -0700 |
| Message-ID | <57205362-8da8-40ed-a79e-9e896b8c696f@googlegroups.com> |
| In reply to | #43338 |
Τη Πέμπτη, 11 Απριλίου 2013 11:20:47 π.μ. UTC+3, ο χρήστης Steven D'Aprano έγραψε: > On Thu, 11 Apr 2013 07:50:19 +0000, Steven D'Aprano wrote: > > > > > On Thu, 11 Apr 2013 00:13:46 -0700, nagia.retsina wrote: > > > > > >> Since now we k ow the problem maybe we can tell metrites.py to open > > >> index.html using utf-8 encoding rather as binary, dont you think? > > > > > > What makes you think it is UTF-8? > > > > > > Last time you tried decoding content as UTF-8, you got an error that it > > > wasn't a legal UTF-8 file. > > > > Oops, sorry, correction. It wasn't a legal UTF-8 string. It was an > > environment variable that was causing the decoding error, since it > > contained illegal bytes for a UTF-8 string. > > > > > > > Where does index.html come from? Whatever program generates that, you > > > need to find out what encoding it is using. Hello steven, index.html was writenn by handcode from me utilizing html + css metrites.py tries to open that script so we must tell it to open as utf-8 text and not as a binary file. How can we do that?
[toc] | [prev] | [next] | [standalone]
| From | Lele Gaifax <lele@metapensiero.it> |
|---|---|
| Date | 2013-04-11 12:45 +0200 |
| Message-ID | <mailman.456.1365677101.3114.python-list@python.org> |
| In reply to | #43346 |
nagia.retsina@gmail.com writes:
> metrites.py tries to open that script so we must tell it to open as
> utf-8 text and not as a binary file.
One way is the following:
from codecs import open
with open('index.html', encoding='utf-8') as f:
content = f.read()
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]
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Date | 2013-04-10 19:08 +0100 |
| Message-ID | <pan.2013.04.10.18.08.37.884000@nowhere.com> |
| In reply to | #43252 |
On Wed, 10 Apr 2013 00:23:46 -0700, nagia.retsina wrote:
> Look at what 'python3 metrites.py' gives me
> File "/root/.local/lib/python2.7/lib/python3.3/os.py", line 669, ...
^^^ ^^^
[toc] | [prev] | [next] | [standalone]
| From | Νίκος Γκρ33κ <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-04-10 11:25 -0700 |
| Message-ID | <551beeb5-1a45-493a-914c-2d7f495871b3@googlegroups.com> |
| In reply to | #43286 |
Τη Τετάρτη, 10 Απριλίου 2013 9:08:38 μ.μ. UTC+3, ο χρήστης Nobody έγραψε: > On Wed, 10 Apr 2013 00:23:46 -0700, nagia.retsina wrote: > > > > > Look at what 'python3 metrites.py' gives me > > > > > File "/root/.local/lib/python2.7/lib/python3.3/os.py", line 669, ... > > ^^^ ^^^ Yes i see it in the traceback but i dont know what it means. Please explain to me. Tahnk you.
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2013-04-10 13:50 -0600 |
| Message-ID | <mailman.422.1365623444.3114.python-list@python.org> |
| In reply to | #43289 |
On Wed, Apr 10, 2013 at 12:25 PM, Νίκος Γκρ33κ <nikos.gr33k@gmail.com> wrote: > Τη Τετάρτη, 10 Απριλίου 2013 9:08:38 μ.μ. UTC+3, ο χρήστης Nobody έγραψε: >> On Wed, 10 Apr 2013 00:23:46 -0700, nagia.retsina wrote: >> >> >> >> > Look at what 'python3 metrites.py' gives me >> >> >> >> > File "/root/.local/lib/python2.7/lib/python3.3/os.py", line 669, ... >> >> ^^^ ^^^ > > Yes i see it in the traceback but i dont know what it means. > Please explain to me. > Tahnk you. It means that there is something very strange about the way that your Python 3.3 is installed, as the libraries appear to be installed under your Python 2.7 library directory.
[toc] | [prev] | [next] | [standalone]
| From | nagia.retsina@gmail.com |
|---|---|
| Date | 2013-04-09 20:16 -0700 |
| Message-ID | <mailman.396.1365563775.3114.python-list@python.org> |
| In reply to | #43231 |
Τη Τετάρτη, 10 Απριλίου 2013 12:34:25 π.μ. UTC+3, ο χρήστης Ian έγραψε: > On Tue, Apr 9, 2013 at 3:10 PM, Νίκος Γκρ33κ <nikos.gr33k@gmail.com> wrote: > > > Hello, iam still trying to alter the code form python 2.6 => 3.3 > > > > > > Everyrging its setup except that unicode error that you can see if you go to http://superhost.gr > > > > > > Can anyone help with this? > > > I even tried to change print() with sys.stdout.buffer() but still i get the same unicode issue. > > > > > > I don't know what to try anymore. > > > > It seems to be failing on the line: > > > > host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] > > > > So the obvious question to ask is: what are the contents of > > os.environ['REMOTE_ADDR'] when this line is reached? > > > > And why are you still trying to solve these sorts of problems on your > > production website? Do you not have a development or staging > > environment? No forget this line. this is not the problem. No i don't have a testing enviroment, i altered all the code form 2.6 to 3.3 in the live enviromtnt. i strongly believe there is somethign goind wrong with the prints(). Thoese are causing the unicode isu es much like as thes changes from: quote = random.choice( list( open( "/home/nikos/www/data/private/quotes.txt", ) ) ) quote = random.choice( list( open( "/home/nikos/www/data/private/quotes.txt", encoding="utf-8" ) ) ) in order for the open() to work.
[toc] | [prev] | [next] | [standalone]
| From | nagia.retsina@gmail.com |
|---|---|
| Date | 2013-04-11 21:36 -0700 |
| Message-ID | <a58ca596-ec71-4d68-a6b0-820b7eb410bd@googlegroups.com> |
| In reply to | #43230 |
Well, can somebody else propose somehting plz? i have paste the whole script and even the necessary snippet that perhaps causing this encoding confusion in 3.3
[toc] | [prev] | [next] | [standalone]
| From | alex23 <wuwei23@gmail.com> |
|---|---|
| Date | 2013-04-11 22:06 -0700 |
| Message-ID | <a0319b6b-f140-4606-89bc-fa3e58031f9c@id10g2000pbc.googlegroups.com> |
| In reply to | #43418 |
On Apr 12, 2:36 pm, nagia.rets...@gmail.com wrote: > Well, can somebody else propose somehting plz? Pay for a professional.
[toc] | [prev] | [next] | [standalone]
| From | nagia.retsina@gmail.com |
|---|---|
| Date | 2013-04-11 22:42 -0700 |
| Message-ID | <1521dbf5-ffa7-4e15-9995-d9e7a733ba62@googlegroups.com> |
| In reply to | #43419 |
Τη Παρασκευή, 12 Απριλίου 2013 8:06:14 π.μ. UTC+3, ο χρήστης alex23 έγραψε: > On Apr 12, 2:36 pm, nagia.rets...@gmail.com wrote: > > > Well, can somebody else propose somehting plz? > > > > Pay for a professional. Just for a simple encoding problem that will be solved by not vene 1 single line of coding? Don't think so.
[toc] | [prev] | [next] | [standalone]
| From | nagia.retsina@gmail.com |
|---|---|
| Date | 2013-04-12 05:50 -0700 |
| Message-ID | <9602aba1-d870-4b03-ba81-44d8af0072ee@googlegroups.com> |
| In reply to | #43421 |
Someone HEEEEEEEEEELP MEEEEEEEEE!!
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-04-12 23:14 +1000 |
| Message-ID | <mailman.518.1365772483.3114.python-list@python.org> |
| In reply to | #43443 |
On Fri, Apr 12, 2013 at 10:50 PM, <nagia.retsina@gmail.com> wrote: > Someone HEEEEEEEEEELP MEEEEEEEEE!! http://youtu.be/VxMYwjp8t0o ChrisA
[toc] | [prev] | [next] | [standalone]
| From | nagia.retsina@gmail.com |
|---|---|
| Date | 2013-04-12 06:18 -0700 |
| Message-ID | <f282c2e1-b621-4cb1-a121-0d3138070a71@googlegroups.com> |
| In reply to | #43444 |
Τη Παρασκευή, 12 Απριλίου 2013 4:14:39 μ.μ. UTC+3, ο χρήστης Chris Angelico έγραψε: > On Fri, Apr 12, 2013 at 10:50 PM, <nagia.retsina@gmail.com> wrote: > > > Someone HEEEEEEEEEELP MEEEEEEEEE!! > > > > http://youtu.be/VxMYwjp8t0o > > > > ChrisA Well, instead of being a smartass it would be nice if you could actually help for once.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-04-12 23:21 +1000 |
| Message-ID | <mailman.520.1365772915.3114.python-list@python.org> |
| In reply to | #43445 |
On Fri, Apr 12, 2013 at 11:18 PM, <nagia.retsina@gmail.com> wrote: > Τη Παρασκευή, 12 Απριλίου 2013 4:14:39 μ.μ. UTC+3, ο χρήστης Chris Angelico έγραψε: >> On Fri, Apr 12, 2013 at 10:50 PM, <nagia.retsina@gmail.com> wrote: >> >> > Someone HEEEEEEEEEELP MEEEEEEEEE!! >> >> http://youtu.be/VxMYwjp8t0o >> >> ChrisA > > > Well, instead of being a smartass it would be nice if you could actually help for once. Yeah, I'm done with that. Your whining ran through my patience a few posts ago. But you should feel special; I clipped that just for you. ChrisA
[toc] | [prev] | [next] | [standalone]
Page 3 of 5 — ← Prev page 1 2 [3] 4 5 Next page →
Back to top | Article view | comp.lang.python
csiph-web