Search code examples
python-3.xsolrpysolr

pysolr: HTTP method POST not supported by this url


I am new to Solr and PySolr and I am trying to create a web-app. I am planning to use PySolr but when I try to run an example script I get errors. Below are the details:

import pysolr

# Setup a Solr instance. The timeout is optional.
solr = pysolr.Solr('http://localhost:8983/solr/', timeout=10)

# How you'd index data.
solr.add([
    {
        "id": "doc_1",
        "title": "A test document",
    },
    {
        "id": "doc_2",
        "title": "The Banana: Tasty or Dangerous?",
    },
])

Then I get an error:

pysolr.SolrError: Solr responded with an error (HTTP 404): [Reason: None]

After looking up I found that the URL entered must not be correct, so I changed it to my collection's URL.

solr = pysolr.Solr('http://localhost:8983/solr/#/gettingstarted/', timeout=10)

Now I get the error below:

pysolr.SolrError: Solr responded with an error (HTTP 405): [Reason: None] 
HTTP method POST is not supported by this URL

There are tons of questions on the above two errors, but all the resources I found are mostly dealing with some other specific scenarios. So, my question is that how do I give pySolr the correct URL and if the second URL is correct then how to deal with the above error.


Solution

  • The # part of an URL is never sent to the server - it's a local anchor that only the client itself should access. The URL you're using is the admin interface URL that the javascript in the admin interface uses to set up the current page to show.

    The core is available directly under /solr, so the correct URL should be http://localhost:8983/solr/gettingstarted/.

    You can also see this in the query interface inside the admin interface when making queries (the URL is shown at the top - you're interested in the part without the select handler).