librelist archives

« back to archive

Unicode broke my blog!

Unicode broke my blog!

From:
Greg Ward
Date:
2012-09-14 @ 00:59
Eek. I just pushed a changeset that adds some Unicode characters
(UTF-8 encoded) to a post. Result: 

  Internal Server Error
  
  The server encountered an internal error and was unable to complete
  your request. Either the server is overloaded or there is an error in
  the application.

Worse, there's nothing in Apache's error.log to indicate where the
problem originates. There's nothing *at all* in Apache's error.log.
The exact response from the server is

  HTTP/1.1 500 INTERNAL SERVER ERROR
  Date: Fri, 14 Sep 2012 00:43:53 GMT
  Server: Apache/2.2.16 (Debian)
  Content-Length: 291
  Vary: Accept-Encoding
  Connection: close
  Content-Type: text/html
  
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
  <title>500 Internal Server Error</title>
  <h1>Internal Server Error</h1>
  <p>The server encountered an internal error and was unable to complete 
your request.  Either the server is overloaded or there is an error in the
application.</p>

If I run blohg in standalone mode, it's fine. So blohg+flask doesn't
seem to mind my UTF-8 content. Does mod_wsgi or Apache barf on UTF-8?
Do I have to declare that my content is UTF-8 somewhere?

I'm running blohg 0.10.1 in a virtualenv, on top of mod_wsgi 3.3 and
Apache 2.2.16, on a Debian 6.0 (squeeze) server.

If you want to try to reproduce this, I've put my entire blog here:

  http://gerg.ca/gward-blog.bundle

as a Mercurial bundle. Download it and clone it.

Any ideas?

Thanks --

        Greg

Re: [blohg] Unicode broke my blog!

From:
Rafael Martins
Date:
2012-09-14 @ 03:47
Hi Greg,

On Thu, Sep 13, 2012 at 9:59 PM, Greg Ward <greg@gerg.ca> wrote:
> Eek. I just pushed a changeset that adds some Unicode characters
> (UTF-8 encoded) to a post. Result:
>
>   Internal Server Error
>
>   The server encountered an internal error and was unable to complete
>   your request. Either the server is overloaded or there is an error in
>   the application.
>
> Worse, there's nothing in Apache's error.log to indicate where the
> problem originates. There's nothing *at all* in Apache's error.log.
> The exact response from the server is
>
>   HTTP/1.1 500 INTERNAL SERVER ERROR
>   Date: Fri, 14 Sep 2012 00:43:53 GMT
>   Server: Apache/2.2.16 (Debian)
>   Content-Length: 291
>   Vary: Accept-Encoding
>   Connection: close
>   Content-Type: text/html
>
>   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
>   <title>500 Internal Server Error</title>
>   <h1>Internal Server Error</h1>
>   <p>The server encountered an internal error and was unable to complete
your request.  Either the server is overloaded or there is an error in the
application.</p>
>
> If I run blohg in standalone mode, it's fine. So blohg+flask doesn't
> seem to mind my UTF-8 content. Does mod_wsgi or Apache barf on UTF-8?
> Do I have to declare that my content is UTF-8 somewhere?
>
> I'm running blohg 0.10.1 in a virtualenv, on top of mod_wsgi 3.3 and
> Apache 2.2.16, on a Debian 6.0 (squeeze) server.
>
> If you want to try to reproduce this, I've put my entire blog here:
>
>   http://gerg.ca/gward-blog.bundle
>
> as a Mercurial bundle. Download it and clone it.
>
> Any ideas?
>

I`m finding this error in several recent blohg deployments. you need
to have your system using an utf-8 locale (verify with 'locale' on
unix-based os) and the environment variable HGENCODING=utf-8. I have
this fixed in the sample wsgi script [1], but not in the
documentation, afair. I'll update the docs to make this thing clear.

[1] http://hg.rafaelmartins.eng.br/blohg/file/24d2e5bbbb37/share/blohg.wsgi#l13

Best regards.

-- 
Rafael Goncalves Martins
http://rafaelmartins.eng.br/

Re: [blohg] Unicode broke my blog!

From:
Greg Ward
Date:
2012-09-14 @ 19:36
On 14 September 2012, Rafael Martins said:
> I`m finding this error in several recent blohg deployments. you need
> to have your system using an utf-8 locale (verify with 'locale' on
> unix-based os) and the environment variable HGENCODING=utf-8. I have
> this fixed in the sample wsgi script [1], but not in the
> documentation, afair. I'll update the docs to make this thing clear.
> 
> [1] http://hg.rafaelmartins.eng.br/blohg/file/24d2e5bbbb37/share/blohg.wsgi#l13

Huh! Indeed, that fixed it. For future reference, here is the patch to
my /etc/apache/blohg.wsgi file:

--- a/apache2/blohg.wsgiThu Sep 13 16:17:56 2012 -0400
+++ b/apache2/blohg.wsgiFri Sep 14 15:34:31 2012 -0400
@@ -1,4 +1,7 @@
+import os
 import site
+
+os.environ['HGENCODING'] = 'utf-8'
 site.addsitedir('/var/lib/venv/blohg/lib/python2.6/site-packages')
 
 from blohg import create_app

Thanks!

-- 
Greg Ward                                http://www.gerg.ca/
If you're not part of the solution, you're part of the precipitate.