{"id":303,"library":"pyasn1-modules","title":"pyasn1-modules","description":"pyasn1-modules is a collection of ASN.1-based protocol modules for Python, built upon the pyasn1 library. The current version is 0.4.2, released on March 28, 2025. The library is actively maintained, with updates addressing compatibility and support for newer Python versions.","status":"active","version":"0.4.2","language":"python","source_language":"en","source_url":"https://github.com/pyasn1/pyasn1-modules","tags":["ASN.1","protocols","pyasn1","X.509","SMIME"],"install":[{"cmd":"pip install pyasn1-modules","lang":"bash","label":"Install pyasn1-modules"}],"dependencies":[{"reason":"Core library for ASN.1 data structures","package":"pyasn1","optional":false}],"imports":[{"note":"Direct imports without the pyasn1_modules prefix will fail.","wrong":"import rfc2459","symbol":"rfc2459","correct":"from pyasn1_modules import rfc2459"}],"quickstart":{"code":"from pyasn1_modules import rfc2459\nfrom pyasn1.codec.der import decoder\n\n# Example DER-encoded certificate (incomplete for brevity)\nder_encoded_cert = b'...'\n\n# Decode the certificate\ncert, _ = decoder.decode(der_encoded_cert, asn1Spec=rfc2459.Certificate())\n\n# Access certificate fields\nsubject = cert['tbsCertificate']['subject']\nprint('Subject:', subject)","lang":"python","description":"Decoding a DER-encoded X.509 certificate using pyasn1-modules."},"warnings":[{"fix":"Upgrade your Python environment to version 3.8 or later.","message":"Dropped support for Python 2.7, 3.6, and 3.7 in version 0.4.0.","severity":"breaking","affected_versions":"0.4.0 and later"},{"fix":"Use the correct import statement: from pyasn1_modules import <module_name>.","message":"Importing modules directly without the pyasn1_modules prefix will result in ImportError.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Install pyasn1 using pip install pyasn1.","message":"Ensure that pyasn1 is installed, as it is a required dependency.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Verify the integrity and correctness of the input DER-encoded data. Ensure it strictly adheres to the X.509 (RFC 2459) standard if `rfc2459.Certificate()` is used. Update both `pyasn1` and `pyasn1-modules` to their latest stable versions (`pip install --upgrade pyasn1 pyasn1-modules`) to ensure compatibility with modern certificate structures, or if parsing a non-standard certificate, ensure the correct `asn1Spec` is provided.","message":"The pyasn1 decoder encountered an unexpected ASN.1 tag during decoding. This typically indicates that the input DER-encoded data does not conform to the specified ASN.1 schema (e.g., rfc2459.Certificate), or that the data itself is malformed. This can also occur if the version of pyasn1-modules providing the schema is incompatible with the structure of the data.","severity":"breaking","affected_versions":"All versions of pyasn1 and pyasn1-modules"},{"fix":"Ensure that the DER-encoded input data is valid and conforms to the expected ASN.1 schema. Verify that the 'asn1Spec' provided to the decoder (e.g., 'decoder.decode(data, asn1Spec=...)') accurately represents the structure of the input data. Inspect the 'TagSet' mentioned in the error message to understand where the mismatch occurs, as it often points to an unexpected ASN.1 type or structure in the input.","message":"Decoding a DER-encoded object with an incorrect ASN.1 schema or a malformed input will result in a 'pyasn1.error.PyAsn1Error' indicating 'TagSet not in asn1Spec'.","severity":"breaking","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-05-12T12:57:33.315Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Ensure `pyasn1-modules` is installed: `pip install pyasn1-modules`. If using a specific protocol module, ensure it's imported correctly, e.g., `from pyasn1_modules import rfc2459`.","cause":"The `pyasn1-modules` package is not installed in the current Python environment or a specific sub-module cannot be found due to an incomplete installation or environment issue.","error":"ModuleNotFoundError: No module named 'pyasn1_modules'"},{"fix":"Force reinstall `pyasn1-modules` and potentially `pyasn1` to resolve potential conflicts: `pip install --upgrade --force-reinstall pyasn1 pyasn1-modules`. If using `conda`, consider creating a new environment and installing dependencies solely with `pip` or ensuring `conda` and `pip` are in sync.","cause":"A dependency, often `google-auth`, requires a specific version of `pyasn1-modules` that is either not installed, or `pkg_resources` cannot locate it due to conflicts, often when using `conda` alongside `pip` or having multiple Python installations.","error":"pkg_resources.DistributionNotFound: The 'pyasn1-modules>=0.2.1' distribution was not found and is required by google-auth"},{"fix":"Upgrade both `pyasn1` and `pyasn1-modules` to their latest compatible versions: `pip install --upgrade pyasn1 pyasn1-modules`.","cause":"This error typically occurs due to an incompatibility between the installed versions of `pyasn1` and `pyasn1-modules`, where `pyasn1-modules` is trying to use an API feature (like `openType`) that is not present or has changed in the installed `pyasn1` version.","error":"TypeError: __init__() got an unexpected keyword argument 'openType'"},{"fix":"Ensure that the `asn1Spec` passed to the `decoder.decode()` function fully defines all potential components and their types within the ASN.1 structure being decoded. Explicitly define each component type within the `Sequence` or `Set` object that acts as the `asn1Spec`.","cause":"This error occurs during decoding when an ASN.1 sequence or set has components that are not explicitly defined in the `asn1Spec` provided to the decoder, making it unable to determine the type of the encountered data.","error":"pyasn1.error.PyAsn1Error: Component type not defined"},{"fix":"Provide a complete and correct `asn1Spec` (an ASN.1 type object from `pyasn1` or `pyasn1-modules`) to the `decoder.decode()` function that accurately reflects the structure of the data being deserialized. For custom types, ensure they are correctly tagged and passed to the decoder.","cause":"This error indicates that the `pyasn1` decoder was unable to match a tag from the incoming BER/DER/CER serialized data with any of the expected ASN.1 types defined in the `asn1Spec` provided, often because the `asn1Spec` is missing or incomplete for the data being decoded.","error":"pyasn1.error.PyAsn1Error: 'not in asn1Spec: None'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":2.5,"disk_size":"20.5M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":2.5,"disk_size":"21M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.1,"mem_mb":2.5,"disk_size":"23.1M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":2.5,"disk_size":"24M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.08,"mem_mb":2.2,"disk_size":"14.9M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.08,"mem_mb":2.2,"disk_size":"15M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":2.5,"disk_size":"14.5M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":2.3,"disk_size":"15M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.06,"mem_mb":2.5,"disk_size":"20.1M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":2.5,"disk_size":"21M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}