Search code examples
pythongoogle-app-engineelasticsearchurllib2httplib

Elasticsearch query gives "No handler for uri" using httplib in Python


I am using the official elasticsearch-py library for connecting to a local instance of Elasticsearch (localhost, port 9200, ES version 1.6.0). This works well in standalone Python scripts, but I cannot get it to work with Google App Engine where I get the following error:

No handler found for uri [http://localhost:9200/transaction/websession/_search] and method [GET]

After some debugging, I have narrowed the problem down to App Engine's use of httplib for the urlfetch RPC proxy.

So basically, I can do this:

r = urllib2.urlopen('http://localhost:9200/transaction/websession/_search')
r.read()

but not this:

c = httplib.HTTPConnection('localhost:9200')
c.request('GET', 'http://localhost:9200/transaction/websession/_search', None, {})
c.getresponse().read()

Is this a bug in Python? Or in Elasticsearch? What am I missing here?


Solution

  • I found the answer. The problem is the current App Engine SDK. The request is created like this:

    c.request('GET', 'http://localhost:9200/transaction/websession/_search', None, {})
    

    when it should just be:

    c.request('GET', '_search', None, {})
    

    The weird thing is that the latest source code version of the urlfetch stub seems to be very different from the shipped SDK.