ShrinkUrl & core: Fix encoding issue related to getUrlFd.

This commit is contained in:
Valentin Lorentz 2014-07-16 05:41:33 +00:00
parent 5446ac13c5
commit ab011a6618
2 changed files with 5 additions and 0 deletions

View File

@ -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)

View File

@ -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)