[FIX] website: seo, url encode params, + handle connection breaks
This commit is contained in:
parent
e4c2da59f8
commit
c7fb787c70
|
@ -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']])
|
||||
|
||||
|
|
Loading…
Reference in New Issue