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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:40:24+00:00 2026-06-15T15:40:24+00:00

I have a Django app that takes tweet data from Twitter’s API and saves

  • 0

I have a Django app that takes tweet data from Twitter’s API and saves it in a MySQL database. As far as I know (I’m still getting my head around the finer points of character encoding) I’m using UTF-8 everywhere, including MySQL encoding and collation, which works fine except when a tweet contains Emoji characters, which I understand use a four-byte encoding. Trying to save them produces the following warnings from Django:

/home/biggleszx/.virtualenvs/myvirtualenv/lib/python2.6/site-packages/django/db/backends/mysql/base.py:86: Warning: Incorrect string value: ‘\xF0\x9F\x98\xAD I…’ for column ‘text’ at row 1
return self.cursor.execute(query, args)

I’m using MySQL 5.1, so using utf8mb4 isn’t an option unless I upgrade to 5.5, which I’d rather not just yet (also from what I’ve read, Django’s support for this isn’t quite production-ready, though this might no longer be accurate). I’ve also seen folks advising the use of BLOB instead of TEXT on affected columns, which I’d also rather not do as I figure it would harm performance.

My question is, then, assuming I’m not too bothered about 100% preservation of the tweet contents, is there a way I can filter out all Emoji characters and replace them with a non-multibyte character, such as the venerable WHITE MEDIUM SMALL SQUARE (U+25FD)? I figure this is the easiest way to save that data given my current setup, though if I’m missing another obvious solution, I’d love to hear it!

FYI, I’m using the stock Python 2.6.5 on Ubuntu 10.04.4 LTS. sys.maxunicode is 1114111, so it’s a UCS-4 build.

Thanks for reading.

  • 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-15T15:40:25+00:00Added an answer on June 15, 2026 at 3:40 pm

    So it turns out this has been answered a few times, I just hadn’t quite got the right Google-fu to find the existing questions.

    • Python, convert 4-byte char to avoid MySQL error "Incorrect string value:"
    • Warning raised by inserting 4-byte unicode to mysql

    Thanks to Martijn Pieters, the solution came from the world of regular expressions, specifically this code (based on his answer to the first link above):

    import re
    try:
        # UCS-4
        highpoints = re.compile(u'[\U00010000-\U0010ffff]')
    except re.error:
        # UCS-2
        highpoints = re.compile(u'[\uD800-\uDBFF][\uDC00-\uDFFF]')
    # mytext = u'<some string containing 4-byte chars>'
    mytext = highpoints.sub(u'\u25FD', mytext)
    

    The character I’m replacing with is the WHITE MEDIUM SMALL SQUARE (U+25FD), FYI, but could be anything.

    For those unfamiliar with UCS, like me, this is a system for Unicode conversion and a given build of Python will include support for either the UCS-2 or UCS-4 variant, each of which has a different upper bound on character support.

    With the addition of this code, the strings seem to persist in MySQL 5.1 just fine.

    Hope this helps anyone else in the same situation!

    • 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 that gets it's data completely from an external source
I have a django app that uses MySQL as the database backend. It's been
I have a Django app that needs to pull the follower_count information from several
I have a Django app that uses MySQL as a backend. I'm having difficulties
I have a Django app that's serving up a RESTful API using tasty-pie. I'm
I have a Django app that use a django-tagging. I need to port this
I have a django app that I made and have implemented a plist into
This is probably a setting error somewhere. I have a django app that works
I have a Django app where multiple teams upload content that will be parsed.
I have a client that has an app built with django. On every page

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.