Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7506283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:12:53+00:00 2026-05-29T22:12:53+00:00

Using python 3.2, I am trying to decode bytes using str(bytes, cp1251) but I

  • 0

Using python 3.2, I am trying to decode bytes using str(bytes, “cp1251”) but I get this error:

Traceback (most recent call last):
  File "C:\---\---\---\---.py", line 4, in <module>
    writetemp.write(str(f.read(), "cp1251"))
  File "C:\Python32\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 19-25: character     maps to <undefined>

As you can see, I specified “cp1251”, but it attempts to use “cp1252.py” to decode instead of “cp1251.py”, which causes the error, I think. Same thing occurs if I try “Windows-1251” instead of “cp1251”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:12:55+00:00Added an answer on May 29, 2026 at 10:12 pm

    Note how what you’re getting is a UnicodeEncodeError, not a UnicodeDecodeError. The error doesn’t come from your str(f.read(), "cp1251") call. Instead, it comes from the writetemp.write() call.

    The str() call decodes the bytes you get from f.read() using cp1251 as the encoding. That works. That gives you a string (which is unicode, in Python 3.) writetemp.write() then has to turn the string back into bytes, by encoding it. It does that using the encoding you passed when opening writetemp, or the default IO encoding (which Python tries to guess at based on various things.) You can see which encoding that is by looking at the encoding attribute of the file object. You’ll probably find it is cp1252. If you want to write in a particular encoding, don’t rely on Python guessing at it; explicitly specify the encoding when you open the file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a program using python-fuse, but I can't get file
I'm using Python 2.5. I'm trying to use this 'with' statement. from __future__ import
I'm trying to create an xml entry that looks like this using python and
I'm trying to teach myself python using Google's AppEngine , and I can't get
I’m playing around with the Stack Overflow API using Python. I’m trying to decode
I'm a beginner to Python trying to decode this javascript sequence. I'm not only
Using Python, I'm trying to parse a string like this: hello I am an
I'm trying to call io_submit using python ctypes. The code I'm writing is supposed
I am using Python 2.6 and am trying to run a simple random number
I am trying to talk to a device using python. I have been handed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.