# Curl command not running from python script

**URL:** <https://discuss.elastic.co/t/curl-command-not-running-from-python-script/187551>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-machine-learning\
**Created:** [June 26, 2019, 11:08am UTC](https://discuss.elastic.co/t/curl-command-not-running-from-python-script/187551 "2019-06-26T11:08:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bharath\_Kumar\_R](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bharath_kumar_r/32/45474_2.png) [@Bharath\_Kumar\_R](https://discuss.elastic.co/u/Bharath_Kumar_R)\
**Post date:** [June 26, 2019, 11:08am UTC](https://discuss.elastic.co/t/curl-command-not-running-from-python-script/187551/1 "2019-06-26T11:08:01Z")

</div>

I tried to run a curl command from a python script to fetch anomaly results. The code is as follows:  
BODY= '{"size": 10000, "query": {"bool": {"filter": [{"term": {"result\_type": "record"}},{"range": {"record\_score": {"gte": 75}}},{ "range" : { "multi\_bucket\_impact" : { "lt": "-4" } } }]}},"script\_fields": {"timestamp\_date": {"script": {"lang": "painless","source": "doc["timestamp"]"}},"record\_score" : {"script": {"lang": "painless","source": "doc["record\_score"].value"}},"SHIPPERID\_CARRIERID" : {"script": {"lang": "painless","source": "doc["partition\_field\_value"]"}}}}'

try:  
output= subprocess.check\_output(["curl","-g","-XGET", "[http://localhost:9200/.ml-anomalies-.write-my\_job\_low\_sum/\_search](http://localhost:9200/.ml-anomalies-.write-my_job_low_sum/_search)" ,"-H" ,"Content-Type: application/json", "-d", BODY])  
print(output)  
except Exception as e :  
print(e)

But I'm getting the full error:

{"error":{"root\_cause":[{"type":"x\_content\_parse\_exception","reason":"[1:261] [script] failed to parse object"}],"type":"x\_content\_parse\_exception","reason":"[1:261] [script] failed to parse object","caused\_by":{"type":"json\_parse\_exception","reason":"Unexpected character ('t' (code 116)): was expecting comma to separate Object entries\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@45adfb41; line: 1, column: 268]"}},"status":400}

Can you explain the cause for this error and how to solve it?

---

<div class="post-metadata">

**Author:** ![richcollier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/richcollier/32/115035_2.png) [@richcollier](https://discuss.elastic.co/u/richcollier)\
**Post date:** [June 26, 2019, 12:08pm UTC](https://discuss.elastic.co/t/curl-command-not-running-from-python-script/187551/2 "2019-06-26T12:08:30Z")

</div>

You probably need to escape the double-quotes of `"timestamp"` since they are inside other double quotes. So, like this:

```auto
"source": "doc[\"timestamp\"]"

```

---

<div class="post-metadata">

**Author:** ![Bharath\_Kumar\_R](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bharath_kumar_r/32/45474_2.png) [@Bharath\_Kumar\_R](https://discuss.elastic.co/u/Bharath_Kumar_R)\
**Post date:** [June 26, 2019, 12:10pm UTC](https://discuss.elastic.co/t/curl-command-not-running-from-python-script/187551/3 "2019-06-26T12:10:54Z")

</div>

Im still getting the error

---

<div class="post-metadata">

**Author:** ![richcollier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/richcollier/32/115035_2.png) [@richcollier](https://discuss.elastic.co/u/richcollier)\
**Post date:** [June 26, 2019, 12:27pm UTC](https://discuss.elastic.co/t/curl-command-not-running-from-python-script/187551/4 "2019-06-26T12:27:21Z")

</div>

Probably need to do the same thing for the other instances of the embedded double quotes, like for

`"doc[\"record_score\"].value"`

and

`"doc[\"partition_field_value\"]"`

---

<div class="post-metadata">

**Author:** ![Bharath\_Kumar\_R](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bharath_kumar_r/32/45474_2.png) [@Bharath\_Kumar\_R](https://discuss.elastic.co/u/Bharath_Kumar_R)\
**Post date:** [June 26, 2019, 2:01pm UTC](https://discuss.elastic.co/t/curl-command-not-running-from-python-script/187551/5 "2019-06-26T14:01:08Z")

</div>

I tried that too and I'm still getting that error

---

<div class="post-metadata">

**Author:** ![EldrosKandar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eldroskandar/32/33188_2.png) [@EldrosKandar](https://discuss.elastic.co/u/EldrosKandar)\
**Post date:** [June 26, 2019, 2:43pm UTC](https://discuss.elastic.co/t/curl-command-not-running-from-python-script/187551/6 "2019-06-26T14:43:01Z")

</div>

It may be a shot in the dark, but have you tried escaping the square brackets in those three values?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 24, 2019, 2:43pm UTC](https://discuss.elastic.co/t/curl-command-not-running-from-python-script/187551/7 "2019-07-24T14:43:05Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
