Skip to content
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

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

Open
YarShev opened this issue Jan 12, 2024 · 7 comments

Comments

@YarShev
Copy link

YarShev commented Jan 12, 2024

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
Copy link
Owner

hugovk commented Jan 12, 2024

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
Copy link
Author

YarShev commented Jan 12, 2024

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
Copy link
Author

YarShev commented Jan 12, 2024

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
Copy link
Owner

hugovk commented Jan 12, 2024

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
Copy link
Author

YarShev commented Jan 12, 2024

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

@hugovk
Copy link
Owner

hugovk commented Jan 12, 2024

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
Copy link
Author

YarShev commented Jan 12, 2024

After replacing SINGLE_BORDER to DEFAULT the issue has gone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants