Skip to content
This repository has been archived by the owner on Mar 5, 2022. It is now read-only.

Error encountered: 'ascii' codec can't encode character: ordinal not in range(128) #131

Closed
jpatrickpark opened this issue Sep 18, 2016 · 3 comments

Comments

@jpatrickpark
Copy link

jpatrickpark commented Sep 18, 2016

The error

Whenever I try to run the program with a query, the program terminates while displaying the search result. These are some of the error messages and the query that caused it.

$ googler a
[ERROR] 'ascii' codec can't encode character '\xa0' in position 154: ordinal not in range(128)
$ googler b
[ERROR] 'ascii' codec can't encode character '\u2122' in position 40: ordinal not in range(128)
$ googler wit
[ERROR] 'ascii' codec can't encode character '\xb7' in position 6: ordinal not in range(128)

Context

I cloned the repository on September 17th at 17:50 PDT, and ran the googler executable file from the repo on linux trusty distribution, running on a chromebook through crouton, using Python 3.4.3.

Example with the whole output

$ googler t

1 T : Summary for AT&T Inc. - Yahoo Finance
http://finance.yahoo.com/q?s=t
View the basic T stock chart on Yahoo Finance. Change the date range, chart type and compare AT&T Inc. against other companies.

2 T-Mobile: Cell Phones | 4G Phones | iPhone and Android Phones
http://www.t-mobile.com/
[ERROR] 'ascii' codec can't encode character '\xa0' in position 143: ordinal not in range(128)

Possible Cause

It seems like the output included some character which should be encoded using UTF-8, but UTF-8 was not set as the default encoding in python in my system.
In fact when I change the default encoding to UTF-8 the output gets successfully printed without error.

Possible solution

It seems like to encode all output using the most appropriate encoding, depending on particular search results, might fix this.

@jarun
Copy link
Owner

jarun commented Sep 18, 2016

Please set your locale to UTF-8. Here's mine:

$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=en_IN.UTF-8
LC_TIME=en_IN.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=en_IN.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=en_IN.UTF-8
LC_NAME=en_IN.UTF-8
LC_ADDRESS=en_IN.UTF-8
LC_TELEPHONE=en_IN.UTF-8
LC_MEASUREMENT=en_IN.UTF-8
LC_IDENTIFICATION=en_IN.UTF-8
LC_ALL=

And here's the output of googler for the same query on my system:

$ googler t

1 T-Mobile: Cell Phones | 4G Phones | iPhone and Android Phones
http://www.t-mobile.com/
Call 844-222-1889 to make a purchase today! Get FREE SHIPPING on the latest cell phones and cell phone
plans, with UNLIMITED DATA and no annual ...

2 ⚡️ (@t) | Twitter
https://twitter.com/t?ref_src=twsrc%5Egoogle%7Ctwcamp%5Eserp%7Ctwgr%5Eauthor

3 T 40.71 1.00 2.52% : AT&T Inc. - Yahoo Finance
http://finance.yahoo.com/q?s=t
View the basic T stock chart on Yahoo Finance. Change the date range, chart type and compare AT&T Inc.
against other companies.

4 T - Wikipedia, the free encyclopedia
https://en.wikipedia.org/wiki/T
T is the 20th letter in the modern English alphabet and the ISO basic Latin alphabet. It is the most
commonly used consonant and the second most common letter ...

@jarun jarun closed this as completed Sep 18, 2016
@monkeynut
Copy link

monkeynut commented Dec 10, 2016

I like to leave my system on C rather than UTF-8. Not for any great reason other than that is what I'm used to and I don't like surprises. I simply added an alias in my ~/.bashrc like so:

alias googler='LC_ALL="en_GB.UTF-8" googler'

and everything works perfectly without affecting anything else at all. Just thought I'd drop this here for anyone else who might not have thought of it and doesn't want to mess with their normal locale settings for whatever reason.

@jarun
Copy link
Owner

jarun commented Dec 11, 2016

Yes, using application-specific locales is a good workaround in case of such constraints. AFAIR, @zmwangx too suggested a similar solution in another defect somewhere. However, it's too environment-specific to add it to the docs.

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

No branches or pull requests

3 participants