fix POST in py3

This commit is contained in:
j 2014-10-04 21:04:55 +02:00
parent f50b02dd64
commit a3c470847d

View file

@ -5,7 +5,7 @@ from __future__ import with_statement, print_function
import os import os
import gzip import gzip
import re import re
from six import BytesIO from six import BytesIO, PY3
import struct import struct
from six.moves import urllib from six.moves import urllib
@ -51,6 +51,8 @@ def open_url(url, data=None, headers=DEFAULT_HEADERS):
if isinstance(url, bytes): if isinstance(url, bytes):
url = url.decode('utf-8') url = url.decode('utf-8')
url = url.replace(' ', '%20') url = url.replace(' ', '%20')
if PY3 and not isinstance(data, bytes):
data = data.encode('utf-8')
req = urllib.request.Request(url, data, headers) req = urllib.request.Request(url, data, headers)
return urllib.request.urlopen(req) return urllib.request.urlopen(req)