Skip to content

Commit

Permalink
MNT support oder requests versions (#817)
Browse files Browse the repository at this point in the history
* MNT support older requests versions

* remove unnecessary comment
  • Loading branch information
adrinjalali authored Apr 4, 2022
1 parent 9edcb30 commit 912078f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ requirements:
- python
- pip
- filelock
- requests <=2.23
- requests
- tqdm
- typing-extensions
- packaging
Expand All @@ -24,7 +24,7 @@ requirements:
- python
- pip
- filelock
- requests <=2.23
- requests
- tqdm
- typing-extensions
- packaging
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ repos:
rev: v4.1.0
hooks:
- id: check-yaml
exclude: .github/conda/meta.yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-case-conflict
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def get_version() -> str:

install_requires = [
"filelock",
"requests>=2.27",
"requests",
"tqdm",
"pyyaml",
"typing-extensions>=3.7.4.3", # to be able to import TypeAlias
Expand Down
3 changes: 2 additions & 1 deletion src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from typing import IO, Dict, Iterable, List, Optional, Tuple, Union

import requests
from requests.exceptions import HTTPError, JSONDecodeError
from requests.exceptions import HTTPError

from .constants import (
ENDPOINT,
Expand All @@ -33,6 +33,7 @@
)
from .utils import logging
from .utils._deprecation import _deprecate_positional_args
from .utils._fixes import JSONDecodeError
from .utils.endpoint_helpers import (
AttributeDictionary,
DatasetFilter,
Expand Down
10 changes: 10 additions & 0 deletions src/huggingface_hub/utils/_fixes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# JSONDecodeError was introduced in requests=2.27 released in 2022.
# This allows us to support older requests for users
# More information: https://github.com/psf/requests/pull/5856
try:
from requests import JSONDecodeError # noqa
except ImportError:
try:
from simplejson import JSONDecodeError # noqa
except ImportError:
from json import JSONDecodeError # noqa

0 comments on commit 912078f

Please # to comment.