vinitkumar / json2xml

json to xml converter in python3
https://json2xml.readthedocs.io/
Other
98 stars 32 forks source link

Import json2xml.json2xml causes an error #209

Closed nrathaus closed 1 month ago

nrathaus commented 1 month ago

Env

Python 3.9.2 (default, Mar 12 2021, 04:06:34) [GCC 10.2.1 20210110] on linux

Version

json2xml-5.0.2

Linux

Linux 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux

Expected behavior

import json2xml.json2xml

No error

Observed behavior

>>> import json2xml.json2xml
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/a/venv/lib/python3.9/site-packages/json2xml/json2xml.py", line 8, in <module>
    from .utils import InvalidDataError
  File "/opt/a/venv/lib/python3.9/site-packages/json2xml/utils.py", line 39, in <module>
    def readfromurl(url: str, params: dict[str, str] | None = None) -> dict[str, str]:
TypeError: unsupported operand type(s) for |: 'types.GenericAlias' and 'NoneType'

Other env using ./venv/lib/python3.10/site-packages/json2xml-4.1.0.dist-info

Python 3.10.12 (main, Mar 22 2024, 16:50:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import json2xml.json2xml
>>> 

Upgrading to 5.0.2 on working env (still fails)

(venv)$ pip3 install json2xml==5.0.2
Collecting json2xml==5.0.2
  Downloading json2xml-5.0.2-py3-none-any.whl (13 kB)
Requirement already satisfied: urllib3 in ./venv/lib/python3.10/site-packages (from json2xml==5.0.2) (2.2.1)
Requirement already satisfied: defusedxml in ./venv/lib/python3.10/site-packages (from json2xml==5.0.2) (0.7.1)
Installing collected packages: json2xml
  Attempting uninstall: json2xml
    Found existing installation: json2xml 4.1.0
    Uninstalling json2xml-4.1.0:
      Successfully uninstalled json2xml-4.1.0
Successfully installed json2xml-5.0.2
(venv) $ python3
Python 3.10.12 (main, Mar 22 2024, 16:50:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import json2xml.json2xml
>>> 

Downgrading from 5. to 4. works

# pip3 install json2xml==4.1.0
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting json2xml==4.1.0
  Downloading https://www.piwheels.org/simple/json2xml/json2xml-4.1.0-py3-none-any.whl (13 kB)
Requirement already satisfied: defusedxml in ./venv/lib/python3.9/site-packages (from json2xml==4.1.0) (0.7.1)
Requirement already satisfied: urllib3 in ./venv/lib/python3.9/site-packages (from json2xml==4.1.0) (2.2.2)
Installing collected packages: json2xml
  Attempting uninstall: json2xml
    Found existing installation: json2xml 5.0.2
    Uninstalling json2xml-5.0.2:
      Successfully uninstalled json2xml-5.0.2
Successfully installed json2xml-4.1.0

[notice] A new release of pip is available: 24.1.2 -> 24.2
[notice] To update, run: pip install --upgrade pip
(venv) # python3
Python 3.9.2 (default, Mar 12 2021, 04:06:34) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import json2xml.json2xml
>>> 
vinitkumar commented 1 month ago

Hi @nrathaus, I am sorry that I missed this issue.

Now coming to the issue at hand, the new version of Json2xml which is 5.0.x has dropped support for Python3.9. It is mentioned in the release notes here (https://github.com/vinitkumar/json2xml/releases/tag/v5.0.0)

https://endoflife.date/python (states that the active support for Python3.9 has already ended). If possible, I would recommend to upgrade to a newer version of Python, if not, it's better to stick to 4.x version of Json2xml. I am anyways going to backport any new feature or security fixes to at least 4.x version of Json2xml.

If there are any questions, please don't hesitate to ask.

nrathaus commented 1 month ago

Thank you for explaining it

It would be a good idea to make the module aware that it's incompatible via its setup file, at the moment pip will happily install it on python3.9 setups

Unfortunately for me, it's an old system (raspberry based) which I can't upgrade to the latest version

vinitkumar commented 1 month ago

@nrathaus You are right, I indeed missed doing it while I thought I did that. Thanks for the suggestion. I will implement it and do a new release.

nrathaus commented 1 month ago

Thanks for the hard work

vinitkumar commented 1 month ago

Hi @nrathaus Thanks again for pointing this mistake.

As corrective measures, I have made two PRS:

And am currently doing a new release to PyPI. The latest version should be 5.0.4.

Could you please check by installing latest json2xml and see if you see the correct warning:

Please run this on a Python3.9 env or virtualenv.

pip install --upgrade json2xml

Once you are satisfied with the solution, please close this issue and don't hesitate to open another ticket should you have another issue with json2xml.

Have a great day ahead. šŸ„‚