Skip to content

incompatible character encodings: UTF-8 and ASCII-8BIT #671

@GBH

Description

@GBH

When trying to create a POST with an attachment I'm running into this issue. Here's a simple example:

params = {
  name: "Gunter",
  attachment: attachment
}

Now, the attachment is a PDF document generate by prawnPDF. Its encoding is ASCII-8BIT. (I'm wrapping it in StringIO thingy just so I can do .read on it)

If I call HTTParty::Request::Body.new(params) everything is great.

However, if I change Gunter to Günter by introducing UTF-8 character I end up with incompatible character encodings: UTF-8 and ASCII-8BIT. Coming from here: https://github.com/jnunemaker/httparty/blob/master/lib/httparty/request/body.rb#L42

It's basically assumes that attachment's .read method will always return an UTF-8 encoded payload. Is that always true? What is a sensible work-around here?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions