Skip to content
Snippets Groups Projects
Commit c7fb787c authored by Denis Ledoux's avatar Denis Ledoux
Browse files

[FIX] website: seo, url encode params, + handle connection breaks

parent e4c2da59
No related branches found
No related tags found
No related merge requests found
......@@ -306,9 +306,13 @@ class Website(openerp.addons.web.controllers.main.Home):
@http.route(['/website/seo_suggest/<keywords>'], type='http', auth="public", website=True)
def seo_suggest(self, keywords):
url = "http://google.com/complete/search?ie=utf8&oe=utf8&output=toolbar&q="
req = urllib2.Request("%s?%s" % (url, keywords))
request = urllib2.urlopen(req)
url = "http://google.com/complete/search"
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']])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment