mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-11 17:56:30 +03:00
Replace requests with urllib
This commit is contained in:
parent
da1f200362
commit
7fbc9e5874
|
@ -2,13 +2,14 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import plac
|
||||
import requests
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import ujson
|
||||
|
||||
from .link import link
|
||||
from ..util import prints, get_package_path
|
||||
from ..compat import url_open, url_error
|
||||
from .. import about
|
||||
|
||||
|
||||
|
@ -56,13 +57,14 @@ def download(model, direct=False):
|
|||
|
||||
|
||||
def get_json(url, desc):
|
||||
r = requests.get(url)
|
||||
if r.status_code != 200:
|
||||
try:
|
||||
r = url_open(url)
|
||||
except url_error as e:
|
||||
msg = ("Couldn't fetch %s. Please find a model for your spaCy "
|
||||
"installation (v%s), and download it manually.")
|
||||
prints(msg % (desc, about.__version__), about.__docs_models__,
|
||||
title="Server error (%d)" % r.status_code, exits=1)
|
||||
return r.json()
|
||||
title="Server error (%d: %s)" % (e.code, e.reason), exits=1)
|
||||
return ujson.load(r)
|
||||
|
||||
|
||||
def get_compatibility():
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
# coding: utf8
|
||||
from __future__ import unicode_literals, print_function
|
||||
|
||||
import requests
|
||||
import pkg_resources
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import ujson
|
||||
|
||||
from ..compat import path2str, locale_escape
|
||||
from ..compat import path2str, locale_escape, url_open, url_error
|
||||
from ..util import prints, get_data_path, read_json
|
||||
from .. import about
|
||||
|
||||
|
@ -15,11 +15,12 @@ def validate():
|
|||
"""Validate that the currently installed version of spaCy is compatible
|
||||
with the installed models. Should be run after `pip install -U spacy`.
|
||||
"""
|
||||
r = requests.get(about.__compatibility__)
|
||||
if r.status_code != 200:
|
||||
try:
|
||||
r = url_open(about.__compatibility__)
|
||||
except url_error as e:
|
||||
prints("Couldn't fetch compatibility table.",
|
||||
title="Server error (%d)" % r.status_code, exits=1)
|
||||
compat = r.json()['spacy']
|
||||
title="Server error (%d: %s)" % (e.code, e.reason), exits=1)
|
||||
compat = ujson.load(r)['spacy']
|
||||
current_compat = compat.get(about.__version__)
|
||||
if not current_compat:
|
||||
prints(about.__compatibility__, exits=1,
|
||||
|
|
Loading…
Reference in New Issue
Block a user