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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:44:01+00:00 2026-05-23T23:44:01+00:00

For some reason i can not seek my utf16 file. It produces ‘UnicodeException: UTF-16

  • 0

For some reason i can not seek my utf16 file. It produces ‘UnicodeException: UTF-16 stream does not start with BOM’. My code:

f = codecs.open(ai_file, 'r', 'utf-16')
seek = self.ai_map[self._cbClass.Text]  #seek is valid int
f.seek(seek)
while True:
    ln = f.readline().strip()

I tried random stuff like first reading something from stream, didnt help. I checked offset that is seeked to using hex editor – string starts at character, not null byte (i guess its good sign, right?)
So how to seek utf-16 in python?

  • 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-23T23:44:02+00:00Added an answer on May 23, 2026 at 11:44 pm

    Well, the error message is telling you why: it’s not reading a byte order mark. The byte order mark is at the beginning of the file. Without having read the byte order mark, the UTF-16 decoder can’t know what order the bytes are in. Apparently it does this lazily, the first time you read, instead of when you open the file — or else it is assuming that the seek() is starting a new UTF-16 stream.

    If your file doesn’t have a BOM, that’s definitely the problem and you should specify the byte order when opening the file (see #2 below). Otherwise, I see two potential solutions:

    1. Read the first two bytes of the file to get the BOM before you seek. You seem to say this didn’t work, indicating that perhaps it’s expecting a fresh UTF-16 stream after the seek, so:

    2. Specify the byte order explicitly by using utf-16-le or utf-16-be as 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

For some reason I can not add reference to MS Word file MSWORD.OLB. It
For some reason, I can not seem to change the default position of an
I've used Scriptaculous before (including effect queues). For some reason, I can not get
For some reason, I can not get this dialog to show up on the
For some reason this PHP code below will not work, I can not figure
for some reason i can not understand im having troubles with mysql_num_rows. Heres the
For some reason i can not format the text of my date in a
For some reason I can not remove an event handler from the FileSystemWatcher. This
There are some breakpoints in my project that for some reason can not be
For some reason I can't find a way to get the equivalents of sqlite's

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.