fix utf-8 urls
This commit is contained in:
parent
5936bc0de0
commit
2d467ea6c6
1 changed files with 6 additions and 2 deletions
|
@ -52,8 +52,12 @@ def get_json(url, data=None, headers=DEFAULT_HEADERS):
|
||||||
return json.loads(read_url(url, data, headers).decode('utf-8'))
|
return json.loads(read_url(url, data, headers).decode('utf-8'))
|
||||||
|
|
||||||
def open_url(url, data=None, headers=DEFAULT_HEADERS):
|
def open_url(url, data=None, headers=DEFAULT_HEADERS):
|
||||||
if isinstance(url, bytes):
|
if PY3:
|
||||||
url = url.decode('utf-8')
|
if isinstance(url, bytes):
|
||||||
|
url = url.decode('utf-8')
|
||||||
|
else:
|
||||||
|
if not isinstance(url, bytes):
|
||||||
|
url = url.encode('utf-8')
|
||||||
url = url.replace(' ', '%20')
|
url = url.replace(' ', '%20')
|
||||||
if data and PY3 and not isinstance(data, bytes):
|
if data and PY3 and not isinstance(data, bytes):
|
||||||
data = data.encode('utf-8')
|
data = data.encode('utf-8')
|
||||||
|
|
Loading…
Add table
Reference in a new issue