hugovk / pypistats

Command-line interface to PyPI Stats API to get download stats for Python packages
https://pypistats.org/api/
MIT License
196 stars 28 forks source link

UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-38: ordinal not in range(256) #417

Open YarShev opened 8 months ago

YarShev commented 8 months ago

Hi there,

I wanted to collect some statistics of a package with pypistats but encountered the error.

$ python -m pip install --upgrade pypistats
$ pypistats recent pandas
Traceback (most recent call last):
  File "miniconda3/envs/myenv/bin/pypistats", line 8, in <module>
    sys.exit(main())
  File "miniconda3/envs/myenv/lib/python3.9/site-packages/pypistats/cli.py", line 372, in main
    args.func(args)
  File "miniconda3/envs/myenv/lib/python3.9/site-packages/pypistats/cli.py", line 217, in recent
    print(
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-39: ordinal not in range(256)

Is there something I am doing wrong?

hugovk commented 8 months ago

Maybe it's something to do with"colour" codes to make the headers bold.

What OS/terminal are you using?

Does NO_COLOR=1 pypistats recent pandas work for you?

image

And do other --formats work?

image

YarShev commented 8 months ago

What OS/terminal are you using?

Ubuntu 22.04.3 LTS, terminal putty and tmux as a terminal multiplexer.

Does NO_COLOR=1 pypistats recent pandas work for you?

Same error

And do other --formats work?

Other formats work for me. It looks like the problem is only related to pretty option.

YarShev commented 8 months ago

Btw, I wanted to look at statistics of pandas package for the whole period and got the following.

$ pypistats overall pandas -f md --start-date 2008-01-01

| category        | percent |   downloads |
|:----------------|--------:|------------:|
| with_mirrors    | 100.00% | 853,511,039 |
| without_mirrors |  98.10% | 837,330,101 |
| Total           |         | 853,511,039 |

Date range: 2008-01-01 - 2024-01-11

However, pepy page for pandas shows about 4 B total downloads for the whole period. Do you know why such a difference in the numbers is?

hugovk commented 8 months ago

pypistats.org data is available for the last 180 days. (For longer time periods, pypinfo can help, you'll need an API key and get free quota.)

YarShev commented 8 months ago

Okay, thanks! Should this issue still be open as there is a problem with pretty option?

hugovk commented 8 months ago

Can do, would you like to try editing miniconda3/envs/myenv/lib/python3.9/site-packages/pypistats/__init__.py and replace both SINGLE_BORDER with another option such as DEFAULT?

https://github.com/jazzband/prettytable#setting-a-table-style

For example:

❯ pypistats recent pandas
+-----------+-------------+------------+
|  last_day |  last_month |  last_week |
+-----------+-------------+------------+
| 6,129,470 | 144,080,301 | 36,288,468 |
+-----------+-------------+------------+

I'm wondering if it's one of the border characters, and we should probably do some encoding somewhere.

YarShev commented 8 months ago

After replacing SINGLE_BORDER to DEFAULT the issue has gone.