mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 17:36:30 +03:00
Fix error on urllib
This commit is contained in:
parent
07b8c255a5
commit
b5098079d8
|
@ -9,7 +9,7 @@ import ujson
|
||||||
|
|
||||||
from .link import link
|
from .link import link
|
||||||
from ..util import prints, get_package_path
|
from ..util import prints, get_package_path
|
||||||
from ..compat import url_open, url_error
|
from ..compat import url_read, HTTPError
|
||||||
from .. import about
|
from .. import about
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,13 +58,13 @@ def download(model, direct=False):
|
||||||
|
|
||||||
def get_json(url, desc):
|
def get_json(url, desc):
|
||||||
try:
|
try:
|
||||||
r = url_open(url)
|
data = url_read(url)
|
||||||
except url_error as e:
|
except HTTPError as e:
|
||||||
msg = ("Couldn't fetch %s. Please find a model for your spaCy "
|
msg = ("Couldn't fetch %s. Please find a model for your spaCy "
|
||||||
"installation (v%s), and download it manually.")
|
"installation (v%s), and download it manually.")
|
||||||
prints(msg % (desc, about.__version__), about.__docs_models__,
|
prints(msg % (desc, about.__version__), about.__docs_models__,
|
||||||
title="Server error (%d: %s)" % (e.code, e.reason), exits=1)
|
title="Server error (%d: %s)" % (e.code, e.reason), exits=1)
|
||||||
return ujson.load(r)
|
return ujson.loads(data)
|
||||||
|
|
||||||
|
|
||||||
def get_compatibility():
|
def get_compatibility():
|
||||||
|
|
|
@ -6,7 +6,7 @@ from pathlib import Path
|
||||||
import sys
|
import sys
|
||||||
import ujson
|
import ujson
|
||||||
|
|
||||||
from ..compat import path2str, locale_escape, url_open, url_error
|
from ..compat import path2str, locale_escape, url_read, HTTPError
|
||||||
from ..util import prints, get_data_path, read_json
|
from ..util import prints, get_data_path, read_json
|
||||||
from .. import about
|
from .. import about
|
||||||
|
|
||||||
|
@ -16,11 +16,11 @@ def validate():
|
||||||
with the installed models. Should be run after `pip install -U spacy`.
|
with the installed models. Should be run after `pip install -U spacy`.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
r = url_open(about.__compatibility__)
|
data = url_read(about.__compatibility__)
|
||||||
except url_error as e:
|
except HTTPError as e:
|
||||||
prints("Couldn't fetch compatibility table.",
|
prints("Couldn't fetch compatibility table.",
|
||||||
title="Server error (%d: %s)" % (e.code, e.reason), exits=1)
|
title="Server error (%d: %s)" % (e.code, e.reason), exits=1)
|
||||||
compat = ujson.load(r)['spacy']
|
compat = ujson.loads(data)['spacy']
|
||||||
current_compat = compat.get(about.__version__)
|
current_compat = compat.get(about.__version__)
|
||||||
if not current_compat:
|
if not current_compat:
|
||||||
prints(about.__compatibility__, exits=1,
|
prints(about.__compatibility__, exits=1,
|
||||||
|
|
|
@ -39,9 +39,9 @@ except ImportError:
|
||||||
import urllib2 as urllib
|
import urllib2 as urllib
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from urllib.error import HTTPError as url_error
|
from urllib.error import HTTPError
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from urllib2 import HTTPError as url_error
|
from urllib2 import HTTPError
|
||||||
|
|
||||||
pickle = pickle
|
pickle = pickle
|
||||||
copy_reg = copy_reg
|
copy_reg = copy_reg
|
||||||
|
@ -49,7 +49,6 @@ CudaStream = CudaStream
|
||||||
cupy = cupy
|
cupy = cupy
|
||||||
copy_array = copy_array
|
copy_array = copy_array
|
||||||
urllib = urllib
|
urllib = urllib
|
||||||
url_error = url_error
|
|
||||||
izip = getattr(itertools, 'izip', zip)
|
izip = getattr(itertools, 'izip', zip)
|
||||||
|
|
||||||
is_windows = sys.platform.startswith('win')
|
is_windows = sys.platform.startswith('win')
|
||||||
|
@ -68,7 +67,7 @@ if is_python2:
|
||||||
input_ = raw_input # noqa: F821
|
input_ = raw_input # noqa: F821
|
||||||
json_dumps = lambda data: ujson.dumps(data, indent=2, escape_forward_slashes=False).decode('utf8')
|
json_dumps = lambda data: ujson.dumps(data, indent=2, escape_forward_slashes=False).decode('utf8')
|
||||||
path2str = lambda path: str(path).decode('utf8')
|
path2str = lambda path: str(path).decode('utf8')
|
||||||
url_open = lambda url: urllib.urlopen(url)
|
url_open = urllib.urlopen
|
||||||
|
|
||||||
elif is_python3:
|
elif is_python3:
|
||||||
bytes_ = bytes
|
bytes_ = bytes
|
||||||
|
@ -77,7 +76,16 @@ elif is_python3:
|
||||||
input_ = input
|
input_ = input
|
||||||
json_dumps = lambda data: ujson.dumps(data, indent=2, escape_forward_slashes=False)
|
json_dumps = lambda data: ujson.dumps(data, indent=2, escape_forward_slashes=False)
|
||||||
path2str = lambda path: str(path)
|
path2str = lambda path: str(path)
|
||||||
url_open = lambda url: urllib.request.urlopen(url)
|
url_open = urllib.request.urlopen
|
||||||
|
|
||||||
|
|
||||||
|
def url_read(url):
|
||||||
|
file_ = url_open(url)
|
||||||
|
code = file_.getcode()
|
||||||
|
if code != 200:
|
||||||
|
raise HTTPError(url, code, "Cannot GET url", [], file_)
|
||||||
|
data = file_.read()
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
def b_to_str(b_str):
|
def b_to_str(b_str):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user