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

  • Home
  • SEARCH
  • 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 541139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:18:46+00:00 2026-05-13T10:18:46+00:00

It throws out UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xc2 in position 2: ordinal

  • 0

It throws out “UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xc2 in position 2: ordinal not in range(128)” when executing following code:

filename = 'Spywaj.ttf'
print repr(filename)
>> 'Sp\xc2\x88ywaj.ttf'
filepath = os.path.join('/dirname', filename)

But the file is valid and existed on disk. Filename was extracted from “unzip -l” command. How can join filenames like this?

OS and filesystem

Filesystem: ext3    relatime,errors=remount-ro 0       0
Locale: en_US.UTF-8

Alex’s suggestion os.path.join works now but I still cannot access the file on disk with the filename it joined.

filename = filename.decode('utf-8')
filepath = os.path.join('/dirname', filename)
print filepath
>> /dirname/u'Sp\xc2\x88ywaj.ttf'
print os.path.isfile(filepath)
>> False

new_filepath = filepath.encode('Latin-1').encode('utf-8')
print new_filepath
>> /dirname/u'Sp\xc2\x88ywaj.ttf'
print type(filepath)
>> <type 'unicode'>
print os.path.isfile(new_filepath)
>> False

valid_filepath = glob.glob('/dirname/*.ttf')[0]
print valid_filepath
>> /dirname/Spywaj.ttf (SO cannot display the chars in filename)
print type(valid_filepath)
>> <type 'str'>
print os.path.isfile(valid_filepath)
>> True
  • 1 1 Answer
  • 2 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-13T10:18:47+00:00Added an answer on May 13, 2026 at 10:18 am

    In both Latin-1 (ISO-8859-1) and Windows-1252, 0xc2 would a capital A with a circumflex accent… doesn’t seem to be anywhere in the code you show! Can you please add a

    print repr(filename)
    

    before the os.path.join call (and also put the '/dirname' in a variable and print its repr for completeness?). I’m thinking that maybe that stray character is there but you’re not seeing it for some reason — the repr will reveal it.

    If you do have a Latin-1 (or Win-1252) non-Ascii character in your filename, you have to use Unicode — and/or, depending on your OS and filesystem, some specific encoding thereof.

    Edit: the OP confirms, thanks to repr, that there are actually two bytes that can’t possibly be ASCII — 0xc2 then 0x88, corresponding to what the OP thinks is one lowercase L.
    Well, that sequence would be a Unicode uppercase A with caret (codepoint 0x88) in the justly popular UTF-8 encoding – how that could look like a lowercase L to the OP beggars explanation, but I imagine some fonts could be graphically crazy enough to afford such confusion.

    So I would first try filename = filename.decode('utf-8') — that should allow the os.path.join to work. If open then balks at the resulting Unicode string (it might work, depending on the filesystem and OS), next attempt is to try using that Unicode object’s .encode('Latin-1') and .encode('utf-8'). If none of the encodings work, information on the OS and filesystem in use, which the OP, I believe, hasn’t given yet, becomes crucial.

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

Sidebar

Ask A Question

Stats

  • Questions 306k
  • Answers 306k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If I understand correctly, you want to pass the iteration… May 13, 2026 at 9:15 pm
  • Editorial Team
    Editorial Team added an answer You need to wait for the flex container to be… May 13, 2026 at 9:15 pm
  • Editorial Team
    Editorial Team added an answer You can't email the password to the user, because you… May 13, 2026 at 9:15 pm

Related Questions

My webpages are served by a script that dynamically imports a bunch of files
What's the best method to debug Django's url configurations? Sometime it just throw out
Please redirect me if a similar question exists.. I haven't been able to find
I'm using the following: Fluently.Configure() .Database(MsSqlConfiguration.MsSql2005.ConnectionString(connectionString)) .Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Incident>() .Where(t => t.Namespace.StartsWith(EDA.DomainModel.POCO)))) .ExposeConfiguration(BuildSchema) .BuildSessionFactory();
I have the following code, which splits up a Vector into a string vector

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.