-
-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix index out of range error when data not found #438
Conversation
b4f1176
to
bf43ebc
Compare
Running against a project which doesn't exist on PyPI and getting results in JSON format: ❯ pypistats python_major testbrojct -f json
{"data": [], "package": "testbrojct", "type": "python_major_downloads"} However, we still get the error when asking for results in other formats: ❯ pypistats python_major testbrojct
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.12/bin/pypistats", line 8, in <module>
sys.exit(main())
^^^^^^
File "/Users/hugo/github/pypistats/src/pypistats/cli.py", line 372, in main
args.func(args)
File "/Users/hugo/github/pypistats/src/pypistats/cli.py", line 258, in python_major
pypistats.python_major(
File "/Users/hugo/github/pypistats/src/pypistats/__init__.py", line 497, in python_major
return pypi_stats_api(endpoint, params, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hugo/github/pypistats/src/pypistats/__init__.py", line 169, in pypi_stats_api
data = _percent(data)
^^^^^^^^^^^^^^
File "/Users/hugo/github/pypistats/src/pypistats/__init__.py", line 322, in _percent
grand_total = _grand_total_value(data)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hugo/github/pypistats/src/pypistats/__init__.py", line 282, in _grand_total_value
if data[0]["category"] in ["with_mirrors", "without_mirrors"]:
~~~~^^^
IndexError: list index out of range ❯ pypistats python_major testbrojct -f html
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.12/bin/pypistats", line 8, in <module>
sys.exit(main())
^^^^^^
File "/Users/hugo/github/pypistats/src/pypistats/cli.py", line 372, in main
args.func(args)
File "/Users/hugo/github/pypistats/src/pypistats/cli.py", line 258, in python_major
pypistats.python_major(
File "/Users/hugo/github/pypistats/src/pypistats/__init__.py", line 497, in python_major
return pypi_stats_api(endpoint, params, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hugo/github/pypistats/src/pypistats/__init__.py", line 169, in pypi_stats_api
data = _percent(data)
^^^^^^^^^^^^^^
File "/Users/hugo/github/pypistats/src/pypistats/__init__.py", line 322, in _percent
grand_total = _grand_total_value(data)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hugo/github/pypistats/src/pypistats/__init__.py", line 282, in _grand_total_value
if data[0]["category"] in ["with_mirrors", "without_mirrors"]:
~~~~^^^
IndexError: list index out of range Let's also handle these too. And please can you add some tests? For example, see a43357d that added the |
I will fix those bugs and add the test. |
Instead of handling with those errors, I prefer to check if res["data"] is an empty list at this line here. I will add the test to check the return message. |
329128c
to
f18dfe2
Compare
for more information, see https://pre-commit.ci
53916cd
to
020d5e4
Compare
fcffe12
to
e478939
Compare
for more information, see https://pre-commit.ci
Do you know why using the Reasonably, both should return 404, because the package does not exist. |
I don't know. If we run with
As you say, the first returns 200 with empty Turns out I already reported this upstream 3 years ago, but there's been no response so we'll have to live with it: |
For this line in the code: pypistats/src/pypistats/__init__.py Line 121 in bfda2c9
Do you think it would be a good idea to delete it, considering it raises an error message? |
This reverts commit c8bb92a.
3bc113b
to
46d8bcc
Compare
Thank you! |
close #437