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 8896049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:56:39+00:00 2026-06-14T23:56:39+00:00

I use chardet for recognize my file encoding, but this error happend : fh=

  • 0

I use chardet for recognize my file encoding, but this error happend :

fh= open("file", mode="r")
sc= chardet.detect(fh)

Traceback (most recent call last):
  File "/home/alireza/test.py", line 19, in <module>
    sc= chardet.detect(fh)
  File "/usr/lib/python3/dist-packages/chardet/__init__.py", line 24, in detect
    u.feed(aBuf)
  File "/usr/lib/python3/dist-packages/chardet/universaldetector.py", line 65, in feed
    aLen = len(aBuf)
TypeError: object of type '_io.TextIOWrapper' has no len()

and i can’t open file with out know the encoding,

fh= open("file", mode="r").read()
sc= chardet.detect(fh)

Traceback (most recent call last):
  File "/home/alireza/workspacee/makecdown/test.py", line 21, in <module>
    fh= open("910.srt", mode="r").read()
  File "/usr/lib/python3.2/codecs.py", line 300, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc7 in position 34: invalid continuation byte

how to use chardet without open file ?! or any way to find out file encoding after/before opening ?

  • 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-06-14T23:56:40+00:00Added an answer on June 14, 2026 at 11:56 pm

    Try opening the file like this

    fh= open("file", mode="rb")
    

    Command Line Tool

    If this does not work, try the command line tool of chardet.
    Description from https://github.com/erikrose/chardet:

    chardet comes with a command-line script which reports on the
    encodings of one or more files:

    % chardetect.py somefile someotherfile
    somefile: windows-1252 with confidence 0.5
    someotherfile: ascii with confidence 1.0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import java.nio.charset.Charsets in my class UriCodec.java,but when i use javac(jdk6) compile this class error.
I am trying to use the Universal Encoding Detector (chardet) in Python to detect
The obvious answer is to use Charset.defaultCharset() but we recently found out that this
use C#,want to upload excel file on google doc. bellow syntax use to upload
Would like to do this: letters: charset ABCDEFGHIJKLMNOPQRSTUVWXYZ pick letters 2 but pick doesn't
I am using chardet 2.01 in python 3.2,the souce code like this site http://getpython3.com/diveintopython3/case-study-porting-chardet-to-python-3.html
I am using Spring MVC's charset filter. This is the URL that I use
If I use the following at the top of my CSS file home.css :
I wanted to use a native Dll in my C# .net application as this:
I use the following code to read data. It throws java.nio.charset.MalformedInputException. The file I

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.