Commits

martinc committed 4619a7b

Support for basic auth on the Solr server

Comments (0)

Files changed (2)

pythonsolr/pysolr.py

     Solr in a directory called '.cache'. The cache can also be an object that subclases httplib2.FileCache
     Not safe to use if multiple threads or processes are going to be running on the same cache.
     """
-    def __init__(self, url, decoder=None, timeout=60,result_class=Results,use_cache=None,cache=None):
+    def __init__(self, url, decoder=None, timeout=60,result_class=Results,use_cache=None,cache=None,username=None,password=None):
         self.decoder = decoder or json.JSONDecoder()
         self.url = url
         self.scheme, netloc, path, query, fragment = urlsplit(url)
             self.http = Http(cache=cache or ".cache",timeout=self.timeout)
         else:
             self.http = Http(timeout=self.timeout)
+        if username and password:
+            self.http.add_credentials(username, password)
             
     def _send_request(self, method, path, body=None, headers=None):
         if TIMEOUTS_AVAILABLE:

pythonsolr/pythonsolr.py

 
 
 class PythonSolr(Solr):
-    def __init__(self, url='http://127.0.0.1:8983/solr/', decoder=None, timeout=60):
-        super(PythonSolr, self).__init__(url, decoder, timeout)
+    def __init__(self, url='http://127.0.0.1:8983/solr/', decoder=None, timeout=60, username=None, password=None):
+        super(PythonSolr, self).__init__(url, decoder, timeout, username=username, password=password)
         
     def search(self, q, **kwargs):
         results = super(PythonSolr, self).search(q, **kwargs)