Problems with escaping input


(Jon Hurlock) #1

Hi All,

I'm having trouble inserting data into elastic search via python, in
particular the problem concerns handling speech/quotation marks (e.g. "). I
have tried escaping the speech marks however, it seems to have no effect,
the following error appears:

jonhurlock@cspcjh
~/h/hadoop-0.20.203.0/playground/py/snap/indexing/elastic: python
curltest.py

  • About to connect() to localhost port 9200 (#0)
  • Trying ::1... * connected
  • Connected to localhost (::1) port 9200 (#0)

POST /twitter/tweet/22499999 HTTP/1.1
User-Agent: PycURL/7.19.5
Host: localhost:9200
Accept: /
Content-Length: 174
Content-Type: application/x-www-form-urlencoded

< HTTP/1.1 400 Bad Request
< Content-Type: application/json; charset=UTF-8
< Content-Length: 229
<

  • Connection #0 to host localhost left intact
  • Closing connection #0
    {"error":"MapperParsingException[Failed to parse]; nested:
    JsonParseException[Unexpected character ('l' (code 108)): was expecting
    comma to separate OBJECT entries\n at [Source: [B@626bb7a7; line: 1, column: 81]]; ","status":400}

I have given some examples in the following gist.

Any help would be much appreciated.

Jon Hurlock


(Shay Banon) #2

The json is simply invalid, why not use a python json lib to build the json?

On Wed, Jun 20, 2012 at 5:41 PM, Jon Hurlock jonhurlock@gmail.com wrote:

Hi All,

I'm having trouble inserting data into elastic search via python, in
particular the problem concerns handling speech/quotation marks (e.g. "). I
have tried escaping the speech marks however, it seems to have no effect,
the following error appears:

jonhurlock@cspcjh~/h/hadoop-0.20.203.0/playground/py/snap/indexing/elastic: python
curltest.py

  • About to connect() to localhost port 9200 (#0)
  • Trying ::1... * connected
  • Connected to localhost (::1) port 9200 (#0)

POST /twitter/tweet/22499999 HTTP/1.1
User-Agent: PycURL/7.19.5
Host: localhost:9200
Accept: /
Content-Length: 174
Content-Type: application/x-www-form-urlencoded

< HTTP/1.1 400 Bad Request
< Content-Type: application/json; charset=UTF-8
< Content-Length: 229
<

  • Connection #0 to host localhost left intact
  • Closing connection #0
    {"error":"MapperParsingException[Failed to parse]; nested:
    JsonParseException[Unexpected character ('l' (code 108)): was expecting
    comma to separate OBJECT entries\n at [Source: [B@626bb7a7; line: 1, column: 81]]; ","status":400}

I have given some examples in the following gist.

https://gist.github.com/2960359

Any help would be much appreciated.

Jon Hurlock


(system) #3