neptune-ai/neptune-client

BUG: neptune import fails with: cannot import name 'JSONDecodeError' from 'requests.exceptions'

kate-ds opened this issue · 3 comments

Describe the bug

cannot import name 'JSONDecodeError' from 'requests.exceptions' appears after importing Neptune

Reproduction

I'm executing this in Hex.tech

import neptune

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-65-ab0992b2f1a7> in <cell line: 1>()
----> 1 import neptune

~/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.9/lib/python3.9/site-packages/neptune/__init__.py in <module>
    105 from neptune.common.patches import apply_patches
    106 from neptune.constants import ANONYMOUS_API_TOKEN
--> 107 from neptune.metadata_containers import (
    108     Model,
    109     ModelVersion,

~/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.9/lib/python3.9/site-packages/neptune/metadata_containers/__init__.py in <module>
     22 ]
     23 
---> 24 from neptune.metadata_containers.metadata_container import MetadataContainer
     25 from neptune.metadata_containers.model import Model
     26 from neptune.metadata_containers.model_version import ModelVersion

~/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.9/lib/python3.9/site-packages/neptune/metadata_containers/metadata_container.py in <module>
     51     Project,
     52 )
---> 53 from neptune.internal.backends.factory import get_backend
     54 from neptune.internal.backends.neptune_backend import NeptuneBackend
     55 from neptune.internal.backends.nql import NQLQuery

~/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.9/lib/python3.9/site-packages/neptune/internal/backends/factory.py in <module>
     21 from neptune.types.mode import Mode
     22 
---> 23 from .hosted_neptune_backend import HostedNeptuneBackend
     24 from .neptune_backend import NeptuneBackend
     25 from .neptune_backend_mock import NeptuneBackendMock

~/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.9/lib/python3.9/site-packages/neptune/internal/backends/hosted_neptune_backend.py in <module>
     39 )
     40 
---> 41 from neptune.common.backends.utils import with_api_exceptions_handler
     42 from neptune.common.exceptions import (
     43     ClientHttpError,

~/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.9/lib/python3.9/site-packages/neptune/common/backends/utils.py in <module>
     38 
     39 from neptune.api.exceptions_utils import handle_json_errors
---> 40 from neptune.api.requests_utils import ensure_json_response
     41 from neptune.common.envs import NEPTUNE_RETRIES_TIMEOUT_ENV
     42 from neptune.common.exceptions import (

~/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.9/lib/python3.9/site-packages/neptune/api/requests_utils.py in <module>
     22 )
     23 
---> 24 from requests.exceptions import JSONDecodeError
     25 
     26 if TYPE_CHECKING:

ImportError: cannot import name 'JSONDecodeError' from 'requests.exceptions' (/home/hexuser/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.9/lib/python3.9/site-packages/requests/exceptions.py)

`

Expected behavior

Successful import

Environment

Python 3.9.12
neptune 1.3.2
requests-2.28.0

Hello @kate-ds 👋

It looks like hex notebooks come with requests==2.26.0 preinstalled.
The JSONDecodeError is available with requests>=2.27. You can upgrade to requests>=2.27 to fix this.

From your environment information, I can see that you have upgraded to requests==2.28.0. However, you will need to restart the kernel to use the updated packages.

I noticed that on Hex, restarting a kernel also removes all user-installed packages. So you might get stuck with an older version of requests that does not include the JSONDecodeError class. I would recommend reaching out to Hex.tech support regarding this.

Meanwhile, you can downgrade to neptune==1.2.0 which works with requests==2.26.0.

Please let me know if this works for you.

Hello @SiddhantSadangi

Thank you for your prompt response and valuable assistance! Installing neptune==1.2.0 as you suggested has resolved my problem with the JSONDecodeError. Now everything is working perfectly with requests==2.26.0.

Thank you for your support and quick resolution!

My pleasure 🤗

Although this does fix the issue for now, I would still recommend you reach out to Hex.tech support so that they can upgrade the preinstalled version of requests. ⬆️

I will be closing this issue now, but please feel free to create a new one or contact us if you have any further questions or concerns.

Have a great day 🌞