http icon indicating copy to clipboard operation
http copied to clipboard

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

Open semoal opened this issue 7 years ago • 4 comments

Hi, i'm having some issues sending a request with form data. I'm getting this error on post call.

10: from /var/lib/gems/2.5.0/gems/http-3.3.0/lib/http/chainable.rb:27:in post' 9: from /var/lib/gems/2.5.0/gems/http-3.3.0/lib/http/client.rb:30:in request' 8: from /var/lib/gems/2.5.0/gems/http-3.3.0/lib/http/client.rb:70:in perform' 7: from /var/lib/gems/2.5.0/gems/http-3.3.0/lib/http/connection.rb:76:in send_request' 6: from /var/lib/gems/2.5.0/gems/http-3.3.0/lib/http/request.rb:115:in stream' 5: from /var/lib/gems/2.5.0/gems/http-3.3.0/lib/http/request/writer.rb:38:in stream' 4: from /var/lib/gems/2.5.0/gems/http-3.3.0/lib/http/request/writer.rb:70:in send_request' 3: from /var/lib/gems/2.5.0/gems/http-3.3.0/lib/http/request/body.rb:37:in each' 2: from /var/lib/gems/2.5.0/gems/http-3.3.0/lib/http/request/body.rb:37:in copy_stream' 1: from /var/lib/gems/2.5.0/gems/http-3.3.0/lib/http/request/body.rb:64:in write' /var/lib/gems/2.5.0/gems/http-3.3.0/lib/http/request/writer.rb:71:in `block in send_request': incompatible character encodings: UTF-8 and ASCII-8BIT (Encoding::CompatibilityError)

I looked it doesnt crash when i remove a file from the form data.

This is my form data: removing file it appears to work correctly.

{:form=>{:_id=>"5a61b17f26ef95e96dd01cd5", :docType=>"DEFAULT", :name=>"a", :clientId=>"57e40c903f9eb69974c0249e", :description=>"a", :entity=>"56d361d7478dc883f1d63bea", :isVisible=>true, :isRequired=>false, :file=>#<HTTP::FormData::File:0x0000557712865f68 @io=#<File:/home/a/a/a/lib/upload/a-_OP-201800848_a_a_a_a.pdf>, @content_type="application/octet-stream", @filename="a-_OP-201800848_a_a_a_a.pdf">}} I don't know what to do now..

semoal avatar Jul 12 '18 09:07 semoal

Ruby version: 2.5.0 and 2.4.4 has this bug Rails version 5.2.0 HTTP version 3.3.0

semoal avatar Jul 13 '18 11:07 semoal

No updates?

semoal avatar Jul 22 '18 18:07 semoal

Hm. That's definitely a bug. I'll be happy to look at once will have time (next week).

ixti avatar Jul 22 '18 19:07 ixti

Could this bug be solved by always encoding the headers UTF-8 to ASCII-8BIT? I've done that in a fork and it seems to have solved this issue however don't fully understand the repercussions of that change.

      def send_request
        # It's important to send the request in a single write call when
        # possible in order to play nicely with Nagle's algorithm. Making
        # two writes in a row triggers a pathological case where Nagle is
        # expecting a third write that never happens.
        
        # Convert headers to binary string to prevent Encoding::CompatibilityError's
        data = join_headers.b

mikeastock avatar Aug 08 '18 05:08 mikeastock