From ab011a661860cf88333a87bca705756d8ad8af09 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Wed, 16 Jul 2014 05:41:33 +0000 Subject: [PATCH] ShrinkUrl & core: Fix encoding issue related to getUrlFd. --- plugins/ShrinkUrl/plugin.py | 3 +++ src/utils/web.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/plugins/ShrinkUrl/plugin.py b/plugins/ShrinkUrl/plugin.py index d073edabb..7f2b4c0bf 100644 --- a/plugins/ShrinkUrl/plugin.py +++ b/plugins/ShrinkUrl/plugin.py @@ -29,6 +29,7 @@ ### import re +import sys import time import json import urllib @@ -266,6 +267,8 @@ class ShrinkUrl(callbacks.PluginRegexp): headers['content-type'] = 'application/json' data = json.dumps({'longUrl': url}) text = utils.web.getUrl(self._gooApi, data=data, headers=headers) + if sys.version_info[0] >= 3 and isinstance(text, bytes): + text = text.decode() googl = json.loads(text)['id'] if googl: self.db.set('goo', url, googl) diff --git a/src/utils/web.py b/src/utils/web.py index e26b2d224..0f18899db 100644 --- a/src/utils/web.py +++ b/src/utils/web.py @@ -108,6 +108,8 @@ def getUrlFd(url, headers=None, data=None, timeout=None): a dict and string, respectively, as per urllib2.Request's arguments.""" if headers is None: headers = defaultHeaders + if sys.version_info[0] >= 3 and isinstance(data, str): + data = data.encode() try: if not isinstance(url, urllib2.Request): (scheme, loc, path, query, frag) = urlparse.urlsplit(url)