pombreda / cdpedia

Automatically exported from code.google.com/p/cdpedia
0 stars 0 forks source link

problema de encoding en web_app.CDPedia.on_institucional #146

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. arrancar el server con cdpedia.py
2. apuntar el navegador a http://localhost:8000/institucional/cc-by-sa.html
3. deberia aparecer una pagina normal, en cambio aparece una pagina de error 
con un  recuadro superior mencionando un problema de encodings

Para facilitar el debugging web_app.py se modificó para que saque los 
tracebacks al log tal como se menciona en [0]; con esta modificacion aparece el 
traceback:

127.0.0.1 - - [02/Oct/2012 16:23:47] "GET /institucional/cc-by-sa.html 
HTTP/1.1" 500 -
Traceback (most recent call last):
  File "D:\tmp\cd_mini_3\cdpedia\src\third_party\werkzeug\wsgi.py", line 409, in __call__
    return self.app(environ, start_response)
  File "D:\tmp\cd_mini_3\cdpedia\src\web\web_app.py", line 288, in wsgi_app
    response = self.dispatch_request(request)
  File "D:\tmp\cd_mini_3\cdpedia\src\web\web_app.py", line 272, in dispatch_request
    return getattr(self, 'on_' + endpoint)(request, **values)
  File "D:\tmp\cd_mini_3\cdpedia\src\web\web_app.py", line 165, in on_institucional
    asset=data.decode("utf-8")
  File "D:\tmp\cd_mini_3\cdpedia\src\web\web_app.py", line 266, in render_template
    return Response(t.render(context), mimetype='text/html')
  File "D:\tmp\cd_mini_3\cdpedia\src\third_party\jinja2\environment.py", line 894, in render
    return self.environment.handle_exception(exc_info, True)
  File "D:\tmp\cd_mini_3\cdpedia\src\web\templates\institucional.html", line 1, in top-level template code
    {% extends "cdpedia_base.html" %}
  File "D:\tmp\cd_mini_3\cdpedia\src\web\templates\cdpedia_base.html", line 1, in top-level template code
    {% extends "layout.html" %}
  File "D:\tmp\cd_mini_3\cdpedia\src\web\templates\layout.html", line 5, in top-level template code
    <title>{% block title %}{% endblock %} | CDPedia, la Wikipedia offline</title>
  File "D:\tmp\cd_mini_3\cdpedia\src\web\templates\institucional.html", line 2, in block "title"
    {% block title %}{{title}}{% endblock %}
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 8: ordinal 
not in range(128)

[0] 
http://www.google.com/url?sa=D&q=http://code.google.com/p/cdpedia/issues/detail%
3Fid%3D143%23c4&usg=AFQjCNGjBlahnffMwrK3dWWJ3GRGnQcjrw

Original issue reported on code.google.com by ccanepacc@gmail.com on 2 Oct 2012 at 7:25

GoogleCodeExporter commented 9 years ago
Un workaround seria hacer cosas parecidas o lo que se hizo para issue 144, pero 
en web_app.CDPedia.on_institucional

Modificando el método segun esa idea queda:

    def on_institucional(self, request, path):
        path = os.path.join("institucional", path)
        asset_file = os.path.join(config.DIR_ASSETS, path)
        if os.path.isdir(asset_file):
            print "WARNING: ", repr(asset_file), "es un directorio"
            raise NotFound()
        if not os.path.exists(asset_file):
            print "WARNING: no pudimos encontrar", repr(asset_file)
            raise NotFound()

        data = open(asset_file, "rb").read()
        title = utils.get_title_from_data(data)
        if isinstance(title, str):
            title = title.decode("utf-8")
        if isinstance(data, str):
            asset = data.decode("utf-8")
        else:
            asset = data
        return self.render_template('institucional.html',
            title=title,
            asset=asset
        )

La pagina en cuestión rinde bien con este codigo.

Parece chancho, no ?

Adjuntado el web_app.py con esta modificacion y la que manda tracebacks hacia 
el log

Original comment by ccanepacc@gmail.com on 2 Oct 2012 at 7:39

Attachments:

GoogleCodeExporter commented 9 years ago
Para mi lo ideal es que get_title_from_data devuelva unicode directamente. Les 
parece?

Original comment by gringotu...@gmail.com on 2 Oct 2012 at 7:50

GoogleCodeExporter commented 9 years ago

Original comment by gringotu...@gmail.com on 2 Oct 2012 at 7:51

GoogleCodeExporter commented 9 years ago

Original comment by facundob...@gmail.com on 10 Oct 2012 at 1:01

GoogleCodeExporter commented 9 years ago
Fixed in r392.

Original comment by facundob...@gmail.com on 11 Oct 2012 at 8:28