pyca / cryptography

cryptography is a package designed to expose cryptographic primitives and recipes to Python developers.
https://cryptography.io
Other
6.61k stars 1.52k forks source link

AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms' #9543

Closed danielstankw closed 1 year ago

danielstankw commented 1 year ago

I know the issue was raised before Issue but I cant find solution.

My versions:

The issue happens when I try to send artifact using mlflow to s3 bucket

Replicating the issue:

import mlflow
with mlflow.start_run():
    mlflow.log_artifact("test.txt")

Where test.txt is a local test text file.

Error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[6], line 3
      1 with mlflow.start_run():
      2     # Log an artifact (like an output model, image, or another output file)
----> 3     mlflow.log_artifact("test.txt")

File ~/.local/lib/python3.10/site-packages/mlflow/tracking/fluent.py:877, in log_artifact(local_path, artifact_path)
    854 """
    855 Log a local file or directory as an artifact of the currently active run. If no run is
    856 active, this method will create a new active run.
   (...)
    874         mlflow.log_artifact("features.txt")
    875 """
    876 run_id = _get_or_start_run().info.run_id
--> 877 MlflowClient().log_artifact(run_id, local_path, artifact_path)

File ~/.local/lib/python3.10/site-packages/mlflow/tracking/client.py:1091, in MlflowClient.log_artifact(self, run_id, local_path, artifact_path)
   1056 def log_artifact(self, run_id, local_path, artifact_path=None) -> None:
   1057     """
   1058     Write a local file or directory to the remote ``artifact_uri``.
   1059 
   (...)
   1089         is_dir: False
   1090     """
-> 1091     self._tracking_client.log_artifact(run_id, local_path, artifact_path)

File ~/.local/lib/python3.10/site-packages/mlflow/tracking/_tracking_service/client.py:456, in TrackingServiceClient.log_artifact(self, run_id, local_path, artifact_path)
    454     artifact_repo.log_artifacts(local_path, path_name)
    455 else:
--> 456     artifact_repo.log_artifact(local_path, artifact_path)

File ~/.local/lib/python3.10/site-packages/mlflow/store/artifact/s3_artifact_repo.py:154, in S3ArtifactRepository.log_artifact(self, local_file, artifact_path)
    151     dest_path = posixpath.join(dest_path, artifact_path)
    152 dest_path = posixpath.join(dest_path, os.path.basename(local_file))
    153 self._upload_file(
--> 154     s3_client=self._get_s3_client(), local_file=local_file, bucket=bucket, key=dest_path
    155 )

File ~/.local/lib/python3.10/site-packages/mlflow/store/artifact/s3_artifact_repo.py:111, in S3ArtifactRepository._get_s3_client(self)
    110 def _get_s3_client(self):
--> 111     return _get_s3_client(
    112         access_key_id=self._access_key_id,
    113         secret_access_key=self._secret_access_key,
    114         session_token=self._session_token,
    115     )

File ~/.local/lib/python3.10/site-packages/mlflow/store/artifact/s3_artifact_repo.py:88, in _get_s3_client(access_key_id, secret_access_key, session_token)
     85 # Invalidate cache every `_MAX_CACHE_SECONDS`
     86 timestamp = int(_get_utcnow_timestamp() / _MAX_CACHE_SECONDS)
---> 88 return _cached_get_s3_client(
     89     signature_version,
     90     s3_endpoint_url,
     91     verify,
     92     timestamp,
     93     access_key_id=access_key_id,
     94     secret_access_key=secret_access_key,
     95     session_token=session_token,
     96 )

File ~/.local/lib/python3.10/site-packages/mlflow/store/artifact/s3_artifact_repo.py:51, in _cached_get_s3_client(signature_version, s3_endpoint_url, verify, timestamp, access_key_id, secret_access_key, session_token)
     28 @lru_cache(maxsize=64)
     29 def _cached_get_s3_client(
     30     signature_version,
   (...)
     36     session_token=None,
     37 ):  # pylint: disable=unused-argument
     38     """Returns a boto3 client, caching to avoid extra boto3 verify calls.
     39 
     40     This method is outside of the S3ArtifactRepository as it is
   (...)
     49     we utilise the `timestamp` parameter to invalidate cache.
     50     """
---> 51     import boto3
     52     from botocore.client import Config
     54     # Making it possible to access public S3 buckets
     55     # Workaround for https://github.com/boto/botocore/issues/2442

File ~/.local/lib/python3.10/site-packages/boto3/__init__.py:17
     14 import logging
     16 from boto3.compat import _warn_deprecated_python
---> 17 from boto3.session import Session
     19 __author__ = 'Amazon Web Services'
     20 __version__ = '1.28.40'

File ~/.local/lib/python3.10/site-packages/boto3/session.py:17
     14 import copy
     15 import os
---> 17 import botocore.session
     18 from botocore.client import Config
     19 from botocore.exceptions import DataNotFoundError, UnknownServiceError

File ~/.local/lib/python3.10/site-packages/botocore/session.py:26
     23 import socket
     24 import warnings
---> 26 import botocore.client
     27 import botocore.configloader
     28 import botocore.credentials

File ~/.local/lib/python3.10/site-packages/botocore/client.py:15
      1 # Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License"). You
   (...)
     11 # ANY KIND, either express or implied. See the License for the specific
     12 # language governing permissions and limitations under the License.
     13 import logging
---> 15 from botocore import waiter, xform_name
     16 from botocore.args import ClientArgsCreator
     17 from botocore.auth import AUTH_TYPE_MAPS

File ~/.local/lib/python3.10/site-packages/botocore/waiter.py:18
     14 import time
     16 import jmespath
---> 18 from botocore.docs.docstring import WaiterDocstring
     19 from botocore.utils import get_service_module_name
     21 from . import xform_name

File ~/.local/lib/python3.10/site-packages/botocore/docs/__init__.py:15
      1 # Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License"). You
   (...)
     11 # ANY KIND, either express or implied. See the License for the specific
     12 # language governing permissions and limitations under the License.
     13 import os
---> 15 from botocore.docs.service import ServiceDocumenter
     17 DEPRECATED_SERVICE_NAMES = {'sms-voice'}
     20 def generate_docs(root_dir, session):

File ~/.local/lib/python3.10/site-packages/botocore/docs/service.py:14
      1 # Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License"). You
   (...)
     11 # ANY KIND, either express or implied. See the License for the specific
     12 # language governing permissions and limitations under the License.
     13 from botocore.docs.bcdoc.restdoc import DocumentStructure
---> 14 from botocore.docs.client import ClientDocumenter, ClientExceptionsDocumenter
     15 from botocore.docs.paginator import PaginatorDocumenter
     16 from botocore.docs.waiter import WaiterDocumenter

File ~/.local/lib/python3.10/site-packages/botocore/docs/client.py:17
     15 from botocore.compat import OrderedDict
     16 from botocore.docs.bcdoc.restdoc import DocumentStructure
---> 17 from botocore.docs.example import ResponseExampleDocumenter
     18 from botocore.docs.method import (
     19     document_custom_method,
     20     document_model_driven_method,
     21     get_instance_public_methods,
     22 )
     23 from botocore.docs.params import ResponseParamsDocumenter

File ~/.local/lib/python3.10/site-packages/botocore/docs/example.py:13
      1 # Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License"). You
   (...)
     11 # ANY KIND, either express or implied. See the License for the specific
     12 # language governing permissions and limitations under the License.
---> 13 from botocore.docs.shape import ShapeDocumenter
     14 from botocore.docs.utils import py_default
     17 class BaseExampleDocumenter(ShapeDocumenter):

File ~/.local/lib/python3.10/site-packages/botocore/docs/shape.py:19
      1 # Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License"). You
   (...)
     17 # inherited from a Documenter class with the appropriate methods
     18 # and attributes.
---> 19 from botocore.utils import is_json_value_header
     22 class ShapeDocumenter:
     23     EVENT_NAME = ''

File ~/.local/lib/python3.10/site-packages/botocore/utils.py:37
     35 import botocore
     36 import botocore.awsrequest
---> 37 import botocore.httpsession
     39 # IP Regexes retained for backwards compatibility
     40 from botocore.compat import HEX_PAT  # noqa: F401

File ~/.local/lib/python3.10/site-packages/botocore/httpsession.py:45
     43         warnings.simplefilter("ignore", category=DeprecationWarning)
     44         # Always import the original SSLContext, even if it has been patched
---> 45         from urllib3.contrib.pyopenssl import (
     46             orig_util_SSLContext as SSLContext,
     47         )
     48 except ImportError:
     49     from urllib3.util.ssl_ import SSLContext

File ~/.local/lib/python3.10/site-packages/urllib3/contrib/pyopenssl.py:50
      1 """
      2 TLS with SNI_-support for Python 2. Follow these instructions if you would
      3 like to verify TLS certificates in Python 2. Note, the default libraries do
   (...)
     46 .. _idna: https://github.com/kjd/idna
     47 """
     48 from __future__ import absolute_import
---> 50 import OpenSSL.crypto
     51 import OpenSSL.SSL
     52 from cryptography import x509

File /usr/lib/python3/dist-packages/OpenSSL/__init__.py:8
      1 # Copyright (C) AB Strakt
      2 # See LICENSE for details.
      4 """
      5 pyOpenSSL - A simple wrapper around the OpenSSL library
      6 """
----> 8 from OpenSSL import crypto, SSL
      9 from OpenSSL.version import (
     10     __author__,
     11     __copyright__,
   (...)
     17     __version__,
     18 )
     21 __all__ = [
     22     "SSL",
     23     "crypto",
   (...)
     31     "__version__",
     32 ]

File /usr/lib/python3/dist-packages/OpenSSL/crypto.py:3279
   3259 load_pkcs12 = utils.deprecated(
   3260     load_pkcs12,
   3261     __name__,
   (...)
   3266     DeprecationWarning,
   3267 )
   3270 # There are no direct unit tests for this initialization.  It is tested
   3271 # indirectly since it is necessary for functions like dump_privatekey when
   3272 # using encryption.
   (...)
   3277 # OpenSSL library (and is linked against the same one that cryptography is
   3278 # using)).
-> 3279 _lib.OpenSSL_add_all_algorithms()
   3281 # This is similar but exercised mainly by exception_from_error_queue.  It calls
   3282 # both ERR_load_crypto_strings() and ERR_load_SSL_strings().
   3283 _lib.SSL_load_error_strings()

AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'
ranjansmygit commented 1 year ago

Could you please share any screenshot or explain in details of the impediment.

reaperhulk commented 1 year ago

pyOpenSSL 23.2 does not call OpenSSL_add_all_algorithms so it’s highly likely you have another version being imported somewhere.

danielstankw commented 1 year ago

pyOpenSSL 23.2 does not call OpenSSL_add_all_algorithms so it’s highly likely you have another version being imported somewhere.

Another version of what library? Any recommendations on how to find the problem?

danielstankw commented 1 year ago

Could you please share any screenshot or explain in details of the impediment.

@ranjansmygit I updated the issue description

reaperhulk commented 1 year ago

Your import paths are all coming from a virtualenv with the exception of pyopenssl, which is coming from your OS's package path. That version of pyopenssl is old and incompatible with the version of cryptography you have installed.

github-actions[bot] commented 1 year ago

This issue has been waiting for a reporter response for 3 days. It will be auto-closed if no activity occurs in the next 5 days.

github-actions[bot] commented 1 year ago

This issue has not received a reporter response and has been auto-closed. If the issue is still relevant please leave a comment and we can reopen it.