Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

MNT support older requests versions #817

Merged
merged 2 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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