Search code examples
python-requestsdruid

How to send post request for apache durid in python


I want to send a post requests with SQL query to a druid API. I used requests package to make the request:

    payload = {
        "query": "select count(1) from table1",
        "resultFormat": "array",
        "header": True,
        "typesHeader": True,
        "sqlTypesHeader": True,
        "context": {
            "somekeys":"somevalues"
        }
    }
   
    druidURL = "someurl:8888/durid/v2/sql"

    x = requests.post(druidUrl,json=payload)

The only result I got is code:405.When I inspect the network in Chrome when the POST request succussed with the result on the druid console, the URL and Payload are exactly the same except there is an additional property called Remote Address.


Solution

  • You have a typo in the URL ("durid"):

    import requests
    
    payload = {
        "query": "select 1+1",
        "resultFormat": "array",
        "header": True,
        "typesHeader": True,
        "sqlTypesHeader": True,
        "context": {
            "somekeys":"somevalues"
        }
    }
    
    druidUrl = "http://localhost:8888/druid/v2/sql"
    
    x = requests.post(druidUrl, json=payload)
    
    print(x)