-
Notifications
You must be signed in to change notification settings - Fork 2
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: 'ascii' codec can't encode character u'\xa0' in position 20: ordinal not in range(128) #3
Comments
Thanks! There's some python2 vs python3 differences: python2: >>> '\xa0'.encode('utf-8')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 0: ordinal not in range(128) vs. python3: >>> '\xa0'.encode('utf-8')
b'\xc2\xa0' |
I work:
|
export PYTHONIOENCODING=utf-8 |
Thank you. If you want to submit a pull request, I will review and merge it.
Best,
… On Nov 9, 2019, at 8:38 AM, KrinalPatel11 ***@***.***> wrote:
You need to read the Python Unicode HOWTO. This error is the very first example.
Basically, stop using str to convert from unicode to encoded text / bytes.
Instead, properly use .encode() to encode the string:
p.agent_info = u' '.join((agent_contact, agent_telno)).encode('utf-8').strip()
Here is Full Answer
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
what version python do you have?, and django version?? |
What does this have to do with tracsql?
… On Feb 1, 2021, at 12:50 AM, Hasib Kamal ***@***.***> wrote:
import datetime
import random
import smtplib
MY_EMAIL = ***@***.***"
PASSWORD = "Pp123456"
now = datetime.datetime.now()
day_of_week = now.weekday()
if day_of_week == 0:
with open("quotes.txt", encoding="utf8") as quote_file:
all_quotes = quote_file.readlines()
quote = random.choice(all_quotes)
print(quote)
with smtplib.SMTP("smtp.gmail.com") as connection:
connection.starttls()
connection.login(user=MY_EMAIL, password=PASSWORD)
***@***.***",msg=f"Subject:Hello\n\n{quote}")
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
tnx |
this worked for me: |
I got this error (UnicodeEncodeError: 'ascii' codec can't encode character u'\xab' in position 15: ordinal not in range(128)) on python2 while writing shapefile._Record type data to a csv. Now this is for a few records only, have tried setting env variables as mentioned above but nothing worked, what should be the solution ? Erroneous line: for i in rd.shapefile_records(): |
This is not the right project for that error, we don’t use shapefiles.
… On Aug 19, 2021, at 7:24 AM, AnweshaSen ***@***.***> wrote:
I got this error (UnicodeEncodeError: 'ascii' codec can't encode character u'\xab' in position 15: ordinal not in range(128)) on python2 while writing shapefile._Record type data to a csv. Now this is for a few records only, have tried setting env variables as mentioned above but nothing worked, what should be the solution ?
Erroneous line:
for i in rd.shapefile_records():
writer.writerow(i)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
|
Try setting the system default encoding as utf-8 at the start of the script, so that all strings are encoded using that. Example -
The above should set the default encoding as utf-8 . In most cases, the issue is that when you call str(), python uses the default character encoding to try and encode the bytes you gave it, which in your case are sometimes representations of unicode characters. To fix the problem, you have to tell python how to deal with the string you give it by using .encode('whatever_unicode'). Most of the time, you should be fine using utf-8. So, stop using str() to convert from unicode to encoded text / bytes, properly use .encode() to encode the string:,
For python 3.x ,there is default encoding, hence there will be no issue of encoding. |
you saved my day bro thanks ~~ |
this is a limitation of the str() function
Solution :
in web_ui.py line 187 replace it with
The text was updated successfully, but these errors were encountered: