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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:33:43+00:00 2026-06-01T15:33:43+00:00

I have a queue of text messages in Redis. Let’s say a message in

  • 0

I have a queue of text messages in Redis. Let’s say a message in redis is something like this:

"niño" 

(spot the non standard character).

The rails app displays the queue of messages. When I test locally (Rails 3.2.2, Ruby 1.9.3) everything is fine, but on Heroku cedar (Rails 3.2.2, I believe there is ruby 1.9.2) I get the infamous error: ActionView::Template::Error (invalid byte sequence in UTF-8)

After reading and rereading all I could find online I am still stuck as to how to fix this.

Any help or point to the right direction is greatly appreciated!

edit:

I managed to find a solution. I ended up using Iconv:

string = Iconv.iconv('UTF-8', 'ISO-8859-1', message)[0]

None of the suggested answers i found around seem to work in my case.

  • 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-01T15:33:44+00:00Added an answer on June 1, 2026 at 3:33 pm

    On Heroku, when your app receives the message “niño” from Redis, it is actually getting the four bytes:

     0x6e 0x69 0xf1 0x6f
    

    which, when interpreted as ISO-8859-1 correspond to the characters n, i, ñ and o.

    However, your Rails app assumes that these bytes should be interpreted as UTF-8, and at some point it tries to decode them this way. The third byte in this sequence, 0xf1 looks like this:

    1 1 1 1 0 0 0 1
    

    If you compare this to the table on the Wikipedia page, you can see this byte is the leading byte of a four byte character (it matches the pattern 11110xxx), and as such should be followed by three more continuation bytes that all match the pattern 10xxxxxx. It’s not, instead the next byte is 0x6f (01101111), and so this is invalid utf-8 byte sequence and you get the error you see.

    Using:

    string = message.encode('utf-8', 'iso-8859-1')
    

    (or the Iconv equivalent) tells Ruby to read message as ISO-8859-1 encoded, and then to create the equivalent string in UTF-8 encoding, which you can then use without problems. (An alternative could be to use force_encoding to tell Ruby the correct encoding of the string, but that will likely cause problems later when you try to mix UTF-8 and ISO-8859-1 strings).

    In UTF-8, the string “niño” corresponds to the bytes:

    0x6e 0x69 0xc3 0xb1 0x6f
    

    Note that the first, second and last bytes are the same. The ñ character is encoded as the two bytes 0xc3 0xb1. If you write these out in binary and compare to the table in the Wikipedia again article you’ll see they encode 0xf1, which is the ISO-8859-1 encoding of ñ (since the first 256 unicode codepoints match ISO-8859-1).

    If you take these five bytes and treat them as being ISO-8859-1, then they correspond to the string

    niño
    

    Looking at the ISO-8859-1 codepage, 0xc3 maps to Â, and 0xb1 maps to ±.

    So what’s happening on your local machine is that your app is receiving the five bytes 0x6e 0x69 0xc3 0xb1 0x6f from Redis, which is the UTF-8 representation of “niño”. On Heroku it’s receiving the four bytes 0x6e 0x69 0xf1 0x6f, which is the ISO-8859-1 representation.

    The real fix to your problem will be to make sure the strings being put into Redis are all already UTF-8 (or at least all the same encoding). I haven’t used Redis, but from what I can tell from a brief Google, it doesn’t concern itself with string encodings but simply gives back whatever bytes it’s been given. You should look at whatever process is putting the data into Redis, and ensure that it handles the encoding properly.

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

Sidebar

Related Questions

I don't understand why this code doesn't work: function Messages(type,text) { console.log(In function Message);
I am sending messages to a remote queue, to which I have no control.
Ok this is the scenario... I have a table in Oracle that acts like
I have a web app that sends messages to an Amazon SQS Queue. Amazon
I have created a jabberbot class that I would like to broadcast scheduled messages.
I'd like to make an app to send/receive text messages using a GSM modem.
I'm still new at this threading thingy. Lets say I have 50000 URLs and
i have a function To run messages in a queue. But when I run
I have a message in a Journal of a Private queue (.\Private$\theQueue\Journal$) The message
I'm trying to create simply connect with ActiveMQ using JNDI. I have: Queue named

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.