Repository: ckan/ckan

Issue:
ckan.lib.search.common.SearchError: Could not extract version info from the SOLR schema
**CKAN version**
2.9.3 (deb)

**Describe the bug**
CKAN fails to fetch the Solr schema using basic auth (401s)

**Steps to reproduce**
In ckan.ini
```
solr_url = http://solr:8983/solr/ckan
solr_user = solr
solr_password = pass
```
Then run CKAN with

`ckan run`

**Expected behavior**
CKAN to fetch the Solr schema and version

**Additional details**
```sh
root@ckan-78f8b8bdb5-c72ch:/# ckan run
2021-07-27 03:30:48,904 INFO  [ckan.cli] Using configuration file /etc/ckan/default/ckan.ini
2021-07-27 03:30:48,905 INFO  [ckan.config.environment] Loading static files from public
Traceback (most recent call last):
  File "/usr/lib/ckan/default/bin/ckan", line 11, in <module>
    load_entry_point('ckan', 'console_scripts', 'ckan')()
  File "/usr/lib/ckan/default/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/ckan/default/lib/python3.8/site-packages/click/core.py", line 781, in main
    with self.make_context(prog_name, args, **extra) as ctx:
  File "/usr/lib/ckan/default/lib/python3.8/site-packages/click/core.py", line 700, in make_context
    self.parse_args(ctx, args)
  File "/usr/lib/ckan/default/lib/python3.8/site-packages/click/core.py", line 1212, in parse_args
    rest = Command.parse_args(self, ctx, args)
  File "/usr/lib/ckan/default/lib/python3.8/site-packages/click/core.py", line 1048, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
  File "/usr/lib/ckan/default/lib/python3.8/site-packages/click/core.py", line 1630, in handle_parse_result
    value = invoke_param_callback(self.callback, ctx, self, value)
  File "/usr/lib/ckan/default/lib/python3.8/site-packages/click/core.py", line 123, in invoke_param_callback
    return callback(ctx, param, value)
  File "/usr/lib/ckan/default/src/ckan/ckan/cli/cli.py", line 102, in _init_ckan_config
    ctx.obj = CkanCommand(value)
  File "/usr/lib/ckan/default/src/ckan/ckan/cli/cli.py", line 52, in __init__
    self.app = make_app(self.config)
  File "/usr/lib/ckan/default/src/ckan/ckan/config/middleware/__init__.py", line 56, in make_app
    load_environment(conf)
  File "/usr/lib/ckan/default/src/ckan/ckan/config/environment.py", line 123, in load_environment
    p.load_all()
  File "/usr/lib/ckan/default/src/ckan/ckan/plugins/core.py", line 161, in load_all
    unload_all()
  File "/usr/lib/ckan/default/src/ckan/ckan/plugins/core.py", line 208, in unload_all
    unload(*reversed(_PLUGINS))
  File "/usr/lib/ckan/default/src/ckan/ckan/plugins/core.py", line 236, in unload
    plugins_update()
  File "/usr/lib/ckan/default/src/ckan/ckan/plugins/core.py", line 153, in plugins_update
    environment.update_config()
  File "/usr/lib/ckan/default/src/ckan/ckan/config/environment.py", line 236, in update_config
    search.check_solr_schema_version()
  File "/usr/lib/ckan/default/src/ckan/ckan/lib/search/__init__.py", line 327, in check_solr_schema_version
    raise SearchError(msg)
ckan.lib.search.common.SearchError: Could not extract version info from the SOLR schema
root@ckan-78f8b8bdb5-c72ch:/#
```

Have already applied this patch #6179



Discussion:

Resolving patch:
diff --git a/ckan/lib/search/__init__.py b/ckan/lib/search/__init__.py
--- a/ckan/lib/search/__init__.py
+++ b/ckan/lib/search/__init__.py
@@ -257,16 +257,11 @@ def clear_all():
 def _get_schema_from_solr(file_offset):
     solr_url, solr_user, solr_password = SolrSettings.get()
 
-    http_auth = None
-    if solr_user is not None and solr_password is not None:
-        http_auth = solr_user + ':' + solr_password
-        http_auth = 'Basic {}'.format(base64.b64encode(http_auth.encode('utf8')).strip())
-
     url = solr_url.strip('/') + file_offset
 
-    if http_auth:
+    if solr_user is not None and solr_password is not None:
         response = requests.get(
-            url, headers={'Authorization': http_auth})
+            url, auth=requests.auth.HTTPBasicAuth(solr_user, solr_password))
     else:
         response = requests.get(url)
 


Test patch: