utf-8 codec can t decode byte 0xa9 in position 12527 invalid start byte

+1 vote

while deploying my django localhost code to digital ocean, i am getting this error.

'utf-8' codec can't decode byte 0xa9 in position 12527: invalid start byte
showing below error
home/mesite/djangoprojectdir/homeapp/views.py in index
return render(request, "index.html", {'slide': slide})


/usr/lib/python3.6/codecs.py in decode
  1.         (result, consumed) = self._buffer_decode(data, self.errors, final)

Jun 26, 2020 in Python by Arun
• 130 points
14,406 views

Hi, @There,

It will be helpful if you could post your code here for better understanding.

http://139.59.7.210:8080/

Hi @Gitika, thanks for your reply, please check above link for more details.

Environment:

Request Method: GET
Request URL: http://139.59.7.210:8080/

Django Version: 2.2.2
Python Version: 3.6.9
Installed Applications:
['homeapp.apps.HomeappConfig',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'news',
 'yogablog',
 'ckeditor',
 'social_django',
 'spiritual',
 'babynames',
 'generalnews',
 'django_inlinecss',
 'timezone_field']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Traceback:

File "/home/mesite/djangoprojectdir/djangoprojectenv/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/home/mesite/djangoprojectdir/djangoprojectenv/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "/home/mesite/djangoprojectdir/djangoprojectenv/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/mesite/djangoprojectdir/homeapp/views.py" in index
  11.     return render(request, "index.html", {'slide': slide})

File "/home/mesite/djangoprojectdir/djangoprojectenv/lib/python3.6/site-packages/django/shortcuts.py" in render
  36.     content = loader.render_to_string(template_name, context, request, using=using)

File "/home/mesite/djangoprojectdir/djangoprojectenv/lib/python3.6/site-packages/django/template/loader.py" in render_to_string
  61.         template = get_template(template_name, using=using)

File "/home/mesite/djangoprojectdir/djangoprojectenv/lib/python3.6/site-packages/django/template/loader.py" in get_template
  15.             return engine.get_template(template_name)

File "/home/mesite/djangoprojectdir/djangoprojectenv/lib/python3.6/site-packages/django/template/backends/django.py" in get_template
  34.             return Template(self.engine.get_template(template_name), self)

File "/home/mesite/djangoprojectdir/djangoprojectenv/lib/python3.6/site-packages/django/template/engine.py" in get_template
  143.         template, origin = self.find_template(template_name)

File "/home/mesite/djangoprojectdir/djangoprojectenv/lib/python3.6/site-packages/django/template/engine.py" in find_template
  125.                 template = loader.get_template(name, skip=skip)

File "/home/mesite/djangoprojectdir/djangoprojectenv/lib/python3.6/site-packages/django/template/loaders/base.py" in get_template
  24.                 contents = self.get_contents(origin)

File "/home/mesite/djangoprojectdir/djangoprojectenv/lib/python3.6/site-packages/django/template/loaders/filesystem.py" in get_contents
  24.                 return fp.read()

File "/usr/lib/python3.6/codecs.py" in decode
  321.         (result, consumed) = self._buffer_decode(data, self.errors, final)

Exception Type: UnicodeDecodeError at /
Exception Value: 'utf-8' codec can't decode byte 0xa9 in position 12527: invalid start byte

1 answer to this question.

+1 vote

Hello,

You can always safely read in binary mode and decode it in utf8 with ignore mode. 

In Python something like this:

with open(filename, 'rb') as f:
     lines = [l.decode('utf8', 'ignore') for l in f.readlines()]

OR try this:

data = pd.read_csv("your.csv", encoding='cp1252')

Hope this is helpful!

Thank You!

answered Jun 30, 2020 by Niroj
• 82,840 points
utf-8  codec can t decode byte 0xa9 in position 12527  invalid start byte | Edureka Community
lrcwqomqcg http://www.g63h8wwh6r172r842f836gnph9jv68xos.org/
[url=http://www.g63h8wwh6r172r842f836gnph9jv68xos.org/]ulrcwqomqcg[/url]
<a href="http://www.g63h8wwh6r172r842f836gnph9jv68xos.org/">alrcwqomqcg</a>

Related Questions In Python

0 votes
0 answers

utf-8' codec can't decode byte 0xa0 in position 10: invalid start byte

my code import wordcloud import numpy as np from matplotlib ...READ MORE

Mar 29, 2020 in Python by anonymous
• 120 points
5,255 views
0 votes
2 answers

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xba in position 16: invalid start byte

Thanks, This answer was helpful. READ MORE

answered Jul 11, 2020 in Python by Prashant Chhatrashali
16,820 views
0 votes
1 answer

'utf-8' codec can't decode byte 0x82 in position 16: invalid start byte

Hi@zena, The error is because there is some non-ASCII ...READ MORE

answered Jun 29, 2020 in Python by MD
• 95,460 points
15,930 views
0 votes
2 answers

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte

Hey,  @Himanshu. It's still most likely gzipped data. ...READ MORE

answered Jul 27, 2020 in Python by Gitika
• 65,770 points
24,973 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,443 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,079 views
+3 votes
2 answers

UnicodeDecodeError: "utf-8" codec can't decode byte in position : invalid start byte

You have to use the encoding as latin1 ...READ MORE

answered Jul 23, 2019 in Python by Kunal
247,728 views
0 votes
1 answer

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

Hi, @hala, Regarding your query, you can go ...READ MORE

answered Jun 29, 2020 in Python by Niroj
• 82,840 points
17,581 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP