dakrone / es-mode

An Emacs major mode for interacting with Elasticsearch
GNU General Public License v3.0
196 stars 34 forks source link

Does not support multibyte text in HTTP request error #62

Closed stardiviner closed 6 years ago

stardiviner commented 6 years ago

I do it like this:

GET /accounts/person/_search
{
  "query": {"match": {"desc": "管理"}},
  "size": 1
}

Then reported error:

Debugger entered--Lisp error: (error "Multibyte text in HTTP request: GET /accounts/person/_search HTTP/1.1\015\nMIME-Version: 1.0\015\nConnection: keep-alive\015\nExtension: Security/Digest Security/SSL\015\nHost: localhost:9200\015\nAccept-encoding: gzip\015\nAccept-charset: utf-8;q=1, gb2312;q=0.5, iso-8859-1;q=0.5, big5;q=0.5, iso-2022-jp;q=0.5, shift_jis;q=0.5, euc-tw;q=0.5, euc-jp;q=0.5, euc-jis-2004;q=0.5, euc-kr;q=0.5, us-ascii;q=0.5, utf-7;q=0.5, hz-gb-2312;q=0.5, big5-hkscs;q=0.5, gbk;q=0.5, gb18030;q=0.5, iso-8859-5;q=0.5, koi8-r;q=0.5, koi8-u;q=0.5, cp866;q=0.5, koi8-t;q=0.5, windows-1251;q=0.5, cp855;q=0.5, iso-8859-2;q=0.5, iso-8859-3;q=0.5, iso-8859-4;q=0.5, iso-8859-9;q=0.5, iso-8859-10;q=0.5, iso-8859-13;q=0.5, iso-8859-14;q=0.5, iso-8859-15;q=0.5, windows-1250;q=0.5, windows-1252;q=0.5, windows-1254;q=0.5, windows-1257;q=0.5, cp775;q=0.5, cp850;q=0.5, cp852;q=0.5, cp857;q=0.5, cp858;q=0.5, cp860;q=0.5, cp861;q=0.5, cp863;q=0.5, cp865;q=0.5, cp437;q=0.5, macintosh;q=0.5, next;q=0.5, hp-roman8;q=0.5, adobe-standard-encoding;q=0.5, iso-8859-16;q=0.5, iso-8859-7;q=0.5, windows-1253;q=0.5, cp737;q=0.5, cp851;q=0.5, cp869;q=0.5, iso-8859-8;q=0.5, windows-1255;q=0.5, cp862;q=0.5, iso-2022-jp-2004;q=0.5, cp874;q=0.5, iso-8859-11;q=0.5, viscii;q=0.5, windows-1258;q=0.5, iso-8859-6;q=0.5, windows-1256;q=0.5, iso-2022-cn;q=0.5, iso-2022-cn-ext;q=0.5, iso-2022-jp-2;q=0.5, iso-2022-kr;q=0.5, utf-16le;q=0.5, utf-16be;q=0.5, utf-16;q=0.5, x-ctext;q=0.5\015\nAccept: */*\015\nUser-Agent: URL/Emacs Emacs/27.0.50 (X11; x86_64-pc-linux-gnu)\015\nContent-Type: application/json; charset=UTF-8\015\nContent-length: 57\015\n\015\n{\n  \"query\": {\"match\": {\"desc\": \"\347\256\241\347\220\206\"}},\n  \"size\": 1\n}")
  signal(error ("Multibyte text in HTTP request: GET /accounts/person/_search HTTP/1.1\015\nMIME-Version: 1.0\015\nConnection: keep-alive\015\nExtension: Security/Digest Security/SSL\015\nHost: localhost:9200\015\nAccept-encoding: gzip\015\nAccept-charset: utf-8;q=1, gb2312;q=0.5, iso-8859-1;q=0.5, big5;q=0.5, iso-2022-jp;q=0.5, shift_jis;q=0.5, euc-tw;q=0.5, euc-jp;q=0.5, euc-jis-2004;q=0.5, euc-kr;q=0.5, us-ascii;q=0.5, utf-7;q=0.5, hz-gb-2312;q=0.5, big5-hkscs;q=0.5, gbk;q=0.5, gb18030;q=0.5, iso-8859-5;q=0.5, koi8-r;q=0.5, koi8-u;q=0.5, cp866;q=0.5, koi8-t;q=0.5, windows-1251;q=0.5, cp855;q=0.5, iso-8859-2;q=0.5, iso-8859-3;q=0.5, iso-8859-4;q=0.5, iso-8859-9;q=0.5, iso-8859-10;q=0.5, iso-8859-13;q=0.5, iso-8859-14;q=0.5, iso-8859-15;q=0.5, windows-1250;q=0.5, windows-1252;q=0.5, windows-1254;q=0.5, windows-1257;q=0.5, cp775;q=0.5, cp850;q=0.5, cp852;q=0.5, cp857;q=0.5, cp858;q=0.5, cp860;q=0.5, cp861;q=0.5, cp863;q=0.5, cp865;q=0.5, cp437;q=0.5, macintosh;q=0.5, next;q=0.5, hp-roman8;q=0.5, adobe-standard-encoding;q=0.5, iso-8859-16;q=0.5, iso-8859-7;q=0.5, windows-1253;q=0.5, cp737;q=0.5, cp851;q=0.5, cp869;q=0.5, iso-8859-8;q=0.5, windows-1255;q=0.5, cp862;q=0.5, iso-2022-jp-2004;q=0.5, cp874;q=0.5, iso-8859-11;q=0.5, viscii;q=0.5, windows-1258;q=0.5, iso-8859-6;q=0.5, windows-1256;q=0.5, iso-2022-cn;q=0.5, iso-2022-cn-ext;q=0.5, iso-2022-jp-2;q=0.5, iso-2022-kr;q=0.5, utf-16le;q=0.5, utf-16be;q=0.5, utf-16;q=0.5, x-ctext;q=0.5\015\nAccept: */*\015\nUser-Agent: URL/Emacs Emacs/27.0.50 (X11; x86_64-pc-linux-gnu)\015\nContent-Type: application/json; charset=UTF-8\015\nContent-length: 57\015\n\015\n{\n  \"query\": {\"match\": {\"desc\": \"\347\256\241\347\220\206\"}},\n  \"size\": 1\n}"))
  error("Multibyte text in HTTP request: %s" "GET /accounts/person/_search HTTP/1.1\015\nMIME-Version: 1.0\015\nConnection: keep-alive\015\nExtension: Security/Digest Security/SSL\015\nHost: localhost:9200\015\nAccept-encoding: gzip\015\nAccept-charset: utf-8;q=1, gb2312;q=0.5, iso-8859-1;q=0.5, big5;q=0.5, iso-2022-jp;q=0.5, shift_jis;q=0.5, euc-tw;q=0.5, euc-jp;q=0.5, euc-jis-2004;q=0.5, euc-kr;q=0.5, us-ascii;q=0.5, utf-7;q=0.5, hz-gb-2312;q=0.5, big5-hkscs;q=0.5, gbk;q=0.5, gb18030;q=0.5, iso-8859-5;q=0.5, koi8-r;q=0.5, koi8-u;q=0.5, cp866;q=0.5, koi8-t;q=0.5, windows-1251;q=0.5, cp855;q=0.5, iso-8859-2;q=0.5, iso-8859-3;q=0.5, iso-8859-4;q=0.5, iso-8859-9;q=0.5, iso-8859-10;q=0.5, iso-8859-13;q=0.5, iso-8859-14;q=0.5, iso-8859-15;q=0.5, windows-1250;q=0.5, windows-1252;q=0.5, windows-1254;q=0.5, windows-1257;q=0.5, cp775;q=0.5, cp850;q=0.5, cp852;q=0.5, cp857;q=0.5, cp858;q=0.5, cp860;q=0.5, cp861;q=0.5, cp863;q=0.5, cp865;q=0.5, cp437;q=0.5, macintosh;q=0.5, next;q=0.5, hp-roman8;q=0.5, adobe-standard-encoding;q=0.5, iso-8859-16;q=0.5, iso-8859-7;q=0.5, windows-1253;q=0.5, cp737;q=0.5, cp851;q=0.5, cp869;q=0.5, iso-8859-8;q=0.5, windows-1255;q=0.5, cp862;q=0.5, iso-2022-jp-2004;q=0.5, cp874;q=0.5, iso-8859-11;q=0.5, viscii;q=0.5, windows-1258;q=0.5, iso-8859-6;q=0.5, windows-1256;q=0.5, iso-2022-cn;q=0.5, iso-2022-cn-ext;q=0.5, iso-2022-jp-2;q=0.5, iso-2022-kr;q=0.5, utf-16le;q=0.5, utf-16be;q=0.5, utf-16;q=0.5, x-ctext;q=0.5\015\nAccept: */*\015\nUser-Agent: URL/Emacs Emacs/27.0.50 (X11; x86_64-pc-linux-gnu)\015\nContent-Type: application/json; charset=UTF-8\015\nContent-length: 57\015\n\015\n{\n  \"query\": {\"match\": {\"desc\": \"\347\256\241\347\220\206\"}},\n  \"size\": 1\n}")
  url-http-create-request()
dakrone commented 6 years ago

@stardiviner what version of es-mode are you using? I am able to query with 管理 no problem, retrieving results.

Also, what coding system is the buffer currently using? (and what emacs version?)

stardiviner commented 6 years ago
dakrone commented 6 years ago

It might be related to being on emacs master rather than the emacs-26 branch (which is what I'm running). I'll build a snapshot of master and see if it fails there.

dakrone commented 6 years ago

I wasn't able to reproduce this on either the master or the emacs-26 branch with emacs -q, if you do

emacs -q

And then

(add-to-list 'load-path "~/path/to/requests")
(add-to-list 'load-path "~/path/to/es-mode")
(require 'es-mode)

And then try it, does it reproduce?

stardiviner commented 6 years ago

After following your steps. I got the following output in *Messages*:

executing Es code block...
Mark set
Issuing GET against http://localhost:9200/accounts/person/_search [jq=nil, tablify=nil]
Contacting host: localhost:9200
url-http-create-request: Multibyte text in HTTP request: GET /accounts/person/_search HTTP/1.1
MIME-Version: 1.0
Connection: keep-alive
Extension: Security/Digest Security/SSL
Host: localhost:9200
Accept-encoding: gzip
Accept: */*
User-Agent: URL/Emacs Emacs/27.0.50 (X11; x86_64-pc-linux-gnu)
Content-Type: application/json; charset=UTF-8
Content-length: 57

{
  "query": {"match": {"desc": "管理"}},
  "size": 1
}

But does not get result after execute es src block. Here is a screenshot: image

dakrone commented 6 years ago

Ahh okay, I know what's going on here. I switched the regular es-mode client to use a different http client (requests) but the org-mode execution still uses url-retrieve-synchronously because it needs to be synchronous. I haven't been able to find a way to get url-retrieve-synchronously to work correctly with multibyte things, so I need to switch org-mode execution to a different http client.

stardiviner commented 6 years ago

maybe change to other functions that support multibyte string?

dakrone commented 6 years ago

That is the plan, just have to figure out what that is :)

stardiviner commented 6 years ago

Check out this discusion https://github.com/magit/ghub/issues/12

dakrone commented 6 years ago

I've looked into this before, I am doing the same thing in es-mode where I encode the buffer:

https://github.com/dakrone/es-mode/blob/8c1c601a72fbc9b0e0a80974856abfc679843c86/ob-elasticsearch.el#L87

Still digging

dakrone commented 6 years ago

Huzzah found it (thanks to a link from the link you posted), it turns out the HTTP verb must be encoded also. I've pushed a commit, so let me know if this doesn't fix it for you (I tested your example and it works for me now)