AttributeError: module 'cryptography.utils' has no attribute 'register_interface'

emrpgpycryptographycryptography-utilsregister_interface

I just recently came across an issue when we were bootstrapping one of our EMR clusters, looks like when trying to import pgpy we failed with the following traceback:

Traceback (most recent call last):
  File "/mnt/var/lib/hadoop/steps/s-B2LJDDVVD5Y1/./aws_s3_decrypt.py", line 18, in 
    import pgpy
  File "/usr/local/lib/python3.7/site-packages/pgpy/__init__.py", line 4, in 
    from .pgp import PGPKey
  File "/usr/local/lib/python3.7/site-packages/pgpy/pgp.py", line 27, in 
    from .constants import CompressionAlgorithm
  File "/usr/local/lib/python3.7/site-packages/pgpy/constants.py", line 23, in 
    from ._curves import BrainpoolP256R1, BrainpoolP384R1, BrainpoolP512R1, X25519, Ed25519
  File "/usr/local/lib/python3.7/site-packages/pgpy/_curves.py", line 37, in 
    @utils.register_interface(ec.EllipticCurve)
AttributeError: module 'cryptography.utils' has no attribute 'register_interface'
Command exiting with ret '1'

Apparently the cryptography team released a new version on September 7th 2022 that broke the pgpy library. https://pypi.org/project/cryptography/38.0.1/ We needed to downgrade our version to get things working again. I figured I would post this to see if others run into this, according to the pgpy github page, they are working on a fix. https://github.com/SecurityInnovation/PGPy/issues/402 Here is how I solved it in the meantime, I needed to downgrade the cryptography library.

sudo python3 -m pip install PGPy
sudo python3 -m pip uninstall -y cryptography
sudo python3 -m pip install cryptography==37.0.4