这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 44 additions & 6 deletions conda/core/subdir_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,23 @@
from ..common.path import url_to_path
from ..common.url import join_url, maybe_unquote
from ..core.package_cache_data import PackageCacheData
from ..exceptions import (CondaDependencyError, CondaHTTPError, CondaUpgradeError,
NotWritableError, UnavailableInvalidChannel, ProxyError)
from ..gateways.connection import (ConnectionError, HTTPError, InsecureRequestWarning,
InvalidSchema, SSLError, RequestsProxyError)
from ..exceptions import (
CondaDependencyError,
CondaHTTPError,
CondaUpgradeError,
CondaSSLError,
NotWritableError,
UnavailableInvalidChannel,
ProxyError,
)
from ..gateways.connection import (
ConnectionError,
HTTPError,
InsecureRequestWarning,
InvalidSchema,
SSLError,
RequestsProxyError,
)
from ..gateways.connection.session import CondaSession
from ..gateways.disk import mkdir_p, mkdir_p_sudo_safe
from ..gateways.disk.delete import rm_rf
Expand Down Expand Up @@ -720,8 +733,33 @@ def fetch_repodata_remote_request(url, etag, mod_stamp, repodata_fn=REPODATA_FN)
else:
raise

except (ConnectionError, HTTPError, SSLError) as e:
# status_code might not exist on SSLError
except SSLError as e:
# SSLError: either an invalid certificate or OpenSSL is unavailable
try:
import ssl # noqa: F401
except ImportError:
raise CondaSSLError(
dals(
f"""
OpenSSL appears to be unavailable on this machine. OpenSSL is required to
download and install packages.

Exception: {e}
"""
)
)
else:
raise CondaSSLError(
dals(
f"""
Encountered an SSL error. Most likely a certificate verification issue.

Exception: {e}
"""
)
)

except (ConnectionError, HTTPError) as e:
status_code = getattr(e.response, 'status_code', None)
if status_code in (403, 404):
if not url.endswith('/noarch'):
Expand Down
4 changes: 4 additions & 0 deletions conda/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,10 @@ def __init__(self, message, url, status_code, reason, elapsed_time, response=Non
)


class CondaSSLError(CondaError):
pass


class AuthenticationError(CondaError):
pass

Expand Down
39 changes: 36 additions & 3 deletions conda/gateways/connection/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@
from ...auxlib.logz import stringify
from ...base.context import context
from ...common.io import time_recorder
from ...exceptions import (BasicClobberError, CondaDependencyError, CondaHTTPError,
ChecksumMismatchError, maybe_raise, ProxyError)
from ...exceptions import (
BasicClobberError,
CondaDependencyError,
CondaHTTPError,
CondaSSLError,
ChecksumMismatchError,
maybe_raise,
ProxyError,
)

log = getLogger(__name__)

Expand Down Expand Up @@ -128,7 +135,33 @@ def download(
else:
raise

except (ConnectionError, HTTPError, SSLError) as e:
except SSLError as e:
# SSLError: either an invalid certificate or OpenSSL is unavailable
try:
import ssl # noqa: F401
except ImportError:
raise CondaSSLError(
dals(
f"""
OpenSSL appears to be unavailable on this machine. OpenSSL is required to
download and install packages.

Exception: {e}
"""
)
)
else:
raise CondaSSLError(
dals(
f"""
Encountered an SSL error. Most likely a certificate verification issue.

Exception: {e}
"""
)
)

except (ConnectionError, HTTPError) as e:
help_message = dals("""
An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
Expand Down
19 changes: 19 additions & 0 deletions news/11564-ssl-errors
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* Split `SSLError` from `HTTPError` to help resolve HTTP 000 errors. (#11564)

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
18 changes: 17 additions & 1 deletion tests/core/test_subdir_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
from conda.base.context import context, conda_tests_ctxt_mgmt_def_pol
from conda.common.disk import temporary_content_in_file
from conda.common.io import env_var
from conda.exceptions import CondaSSLError
from conda.gateways.connection import SSLError
from conda.gateways.connection.session import CondaSession
from conda.core.index import get_index
from conda.core.subdir_data import Response304ContentUnchanged, cache_fn_url, read_mod_and_etag, \
SubdirData, fetch_repodata_remote_request, UnavailableInvalidChannel
Expand Down Expand Up @@ -190,7 +193,20 @@ def test_fetch_repodata_remote_request_invalid_noarch(self):
etag = None
mod_stamp = 'Mon, 28 Jan 2019 01:01:01 GMT'
with pytest.raises(UnavailableInvalidChannel):
result = fetch_repodata_remote_request(url, etag, mod_stamp)
fetch_repodata_remote_request(url, etag, mod_stamp)


def test_no_ssl(mocker):
def CondaSession_get(*args, **kwargs):
raise SSLError("Got an SSL error")

mocker.patch.object(CondaSession, "get", CondaSession_get)

url = "https://www.fake.fake/fake/fake/noarch"
etag = None
mod_stamp = "Mon, 28 Jan 2019 01:01:01 GMT"
with pytest.raises(CondaSSLError):
fetch_repodata_remote_request(url, etag, mod_stamp)


def test_subdir_data_prefers_conda_to_tar_bz2():
Expand Down