Ir al contenido
Menú
Se marcó esta pregunta
4161 Vistas

Can someone help me. I would just change the definition of a method of controllers website module. here is my code

import datetime
from itertools import islice
import json
import xml.etree.ElementTree as ET

import logging
import re

import werkzeug.utils
import urllib2
import werkzeug.wrappers
from PIL import Image

import openerp
from openerp.addons.web import http
from openerp.http import request, STATIC_CACHE
from openerp.tools import image_save_for_web
import openerp.addons.website.controllers.main as main

logger = logging.getLogger(__name__)
# Completely arbitrary limits
MAX_IMAGE_WIDTH, MAX_IMAGE_HEIGHT = IMAGE_LIMITS = (1024, 768)
LOC_PER_SITEMAP = 45000
SITEMAP_CACHE_TIME = datetime.timedelta(hours=12)



class Website_extend(main.Website):
     @http.route(['/website/seo_suggest/<keywords>'], type='http', auth="public", website=True)
     def seo_suggest(self, keywords):
         url = "http://google.com/complete/search?hl=fr"
         try:
             req = urllib2.Request("%s&%s" % (url, werkzeug.url_encode({
                 'ie': 'utf8', 'oe': 'utf8', 'output': 'toolbar', 'q': keywords})))
             request = urllib2.urlopen(req)
         except (urllib2.HTTPError, urllib2.URLError):
             return []
         xmlroot = ET.fromstring(request.read())
         return json.dumps([sugg[0].attrib['data'] for sugg in xmlroot if len(sugg) and sugg[0].attrib['data']])   

Avatar
Descartar

@tansadio, I'm also interested in achieving this. I'll write back if I find a solution. Please post back here if you find a solution as well.

Autor

it works well on localhost but on the server it takes me an error like: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 224: ordinal not in range