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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:35:27+00:00 2026-05-22T03:35:27+00:00

In my Django app, I’m uploading a text file, using file.read() to get the

  • 0

In my Django app, I’m uploading a text file, using file.read() to get the contents of the file, and then saving to the database (using Django’s .save() method).

I’m getting the following error:

Environment:

Request Method: POST
Request URL: http://localhost:8000/
Django Version: 1.2.5
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.admin',
 'django.contrib.markup',
 'files']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/lib/pymodules/python2.7/django/core/handlers/base.py" in get_response
  100.                     response = callback(request, *callback_args, **callback_kwargs)
File "/home/mcrittenden/Dropbox/Code/dropdo-django/dropdo/files/views.py" in index
  31.                 return handle_upload(request.FILES['file'])
File "/home/mcrittenden/Dropbox/Code/dropdo-django/dropdo/files/views.py" in handle_upload
  60.     file.save()
File "/usr/lib/pymodules/python2.7/django/db/models/base.py" in save
  458.         self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/usr/lib/pymodules/python2.7/django/db/models/base.py" in save_base
  551.                     result = manager._insert(values, return_id=update_pk, using=using)
File "/usr/lib/pymodules/python2.7/django/db/models/manager.py" in _insert
  195.         return insert_query(self.model, values, **kwargs)
File "/usr/lib/pymodules/python2.7/django/db/models/query.py" in insert_query
  1524.     return query.get_compiler(using=using).execute_sql(return_id)
File "/usr/lib/pymodules/python2.7/django/db/models/sql/compiler.py" in execute_sql
  788.         cursor = super(SQLInsertCompiler, self).execute_sql(None)
File "/usr/lib/pymodules/python2.7/django/db/models/sql/compiler.py" in execute_sql
  732.         cursor.execute(sql, params)
File "/usr/lib/pymodules/python2.7/django/db/backends/util.py" in execute
  15.             return self.cursor.execute(sql, params)
File "/usr/lib/pymodules/python2.7/django/db/backends/mysql/base.py" in execute
  86.             return self.cursor.execute(query, args)
File "/usr/lib/pymodules/python2.7/MySQLdb/cursors.py" in execute
  168.         if not self._defer_warnings: self._warning_check()
File "/usr/lib/pymodules/python2.7/MySQLdb/cursors.py" in _warning_check
  82.                     warn(w[-1], self.Warning, 3)

Exception Type: Warning at /
Exception Value: Incorrect string value: '\xEF\xBB\xBF# W...' for column 'contents' at row 1

I’m assuming (since EF BB BF is the UTF BOM character) this is due to a difference in charset between the DB and the file? Does that sound valid? If so, how do I fix it?

  • 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-22T03:35:28+00:00Added an answer on May 22, 2026 at 3:35 am

    You’re on the right path. Check the charset of your database (is it utf-8?). If it isn’t and you want to use UTF-8, change the charset by using this SQL command

    alter table yourTableName DEFAULT CHARACTER SET utf8;
    

    And read this great tutorial on using UTF-8 in Python if you want to convert your UTF-8 string back.

    You can strip the DOM by using this command

    # Strip the BOM from the beginning of the Unicode string, if it exists
    u.lstrip( unicode( codecs.BOM_UTF8,
    “utf8” ) )

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

Sidebar

Related Questions

I have a Django app, which populates content from a text file, and populates
im using a django app (django adzone), well, but im trying to add banners,
In my django app I was creating an extended user profile using session vars.
Building a django app with some mostly static pages at the front of the
I'm writing a Django app to serve some documentation written in RestructuredText. I have
I have a django app which basically is just a photo album. Right now
In a django app, I need to create twitter user profile urls with following
I have a Django app where there are 2 use cases where I want
I am prototyping a Django web-app that will provide a static media files (PDFs,
I want to run a django app on a hand-held device. It'll need to

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.