Google: Set User-Agent override. (#1426)

With a custom (globally-configured) user-agent, Google may serve a different page, which breaks this plugin.

This override disables this custom user-agent and uses a predefined one, which is known to work.
This commit is contained in:
Gordon Shumway 2020-07-14 08:44:43 -04:00 committed by GitHub
parent 5315cd3275
commit 6e47278b9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -107,6 +107,7 @@ class Google(callbacks.PluginRegexp):
dynamic.irc.nick)
headers = dict(utils.web.defaultHeaders)
headers['Referer'] = ref
headers['User-agent'] = 'Mozilla/5.0 (compatible; utils.web python module)'
opts = {'q': query, 'gbv': '2'}
for (k, v) in options.items():
if k == 'smallsearch':
@ -254,7 +255,7 @@ class Google(callbacks.PluginRegexp):
def _translate(self, sourceLang, targetLang, text):
headers = dict(utils.web.defaultHeaders)
headers['User-Agent'] = ('Mozilla/5.0 (X11; U; Linux i686) '
headers['User-agent'] = ('Mozilla/5.0 (X11; U; Linux i686) '
'Gecko/20071127 Firefox/2.0.0.11')
sourceLang = utils.web.urlquote(sourceLang)