misc: update requests code for py3 (#36515)
This commit is contained in:
parent
f8587a00e1
commit
0f5d4555d2
|
@ -25,7 +25,6 @@ import json
|
|||
import subprocess
|
||||
import tempfile
|
||||
import unicodedata
|
||||
import urllib
|
||||
import hashlib
|
||||
|
||||
import requests
|
||||
|
@ -53,7 +52,7 @@ from . import get_cfg, get_logger, ezt
|
|||
from .errors import ConnectionError
|
||||
from .template import Template
|
||||
|
||||
from django.utils.six import StringIO
|
||||
from django.utils.six import BytesIO, StringIO
|
||||
|
||||
try:
|
||||
subprocess.check_call(['which', 'pdftoppm'], stdout=open('/dev/null', 'w'))
|
||||
|
@ -295,13 +294,11 @@ def _http_request(url, method='GET', body=None, headers={}, cert_file=None, time
|
|||
raise_on_http_errors=False):
|
||||
get_publisher().reload_cfg()
|
||||
|
||||
if url.startswith('http://'):
|
||||
hostname, query = urllib.splithost(url[5:])
|
||||
elif url.startswith('https://'):
|
||||
hostname, query = urllib.splithost(url[6:])
|
||||
else:
|
||||
splitted_url = urlparse.urlsplit(url)
|
||||
if splitted_url.scheme not in ('http', 'https'):
|
||||
raise ConnectionError('invalid scheme in URL %s' % url)
|
||||
|
||||
hostname = splitted_url.netloc
|
||||
timeout = timeout or settings.REQUESTS_TIMEOUT
|
||||
|
||||
try:
|
||||
|
@ -326,7 +323,7 @@ def urlopen(url, data=None):
|
|||
url, 'GET' if data is None else 'POST',
|
||||
body=data,
|
||||
raise_on_http_errors=True)
|
||||
return StringIO(data)
|
||||
return BytesIO(data)
|
||||
|
||||
|
||||
def http_get_page(url, **kwargs):
|
||||
|
|
Loading…
Reference in New Issue