# ImportError: cannot import name 'x509' from 'cryptography.hazmat.bindings.\_rust

**URL:** <https://community.letsencrypt.org/t/importerror-cannot-import-name-x509-from-cryptography-hazmat-bindings-rust/185882>\
**Category:** Help\
**Created:** [October 10, 2022, 2:52pm UTC](https://community.letsencrypt.org/t/importerror-cannot-import-name-x509-from-cryptography-hazmat-bindings-rust/185882 "2022-10-10T14:52:25Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![bagas](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/bagas/32/64649_2.png) [@bagas](https://community.letsencrypt.org/u/bagas)\
**Post date:** [October 10, 2022, 2:52pm UTC](https://community.letsencrypt.org/t/importerror-cannot-import-name-x509-from-cryptography-hazmat-bindings-rust/185882/1 "2022-10-10T14:52:25Z")

</div>

Hello.  
I'm trying to renew my current certificates.

My system FreeBSD 12.3-RELEASE-p7 amd64.  
My version soft:  
rust-1.63.0 = up-to-date with index  
py39-certbot-1.31.0,1 = up-to-date with index  
py39-cryptography-38.0.1 = up-to-date with index  
py39-josepy-1.13.0 = up-to-date with index  
py39-openssl-20.0.1,1 = up-to-date with index

# /usr/local/bin/certbot -q renew --allow-subset-of-names

Traceback (most recent call last):  
File "/usr/local/bin/certbot", line 33, in   
sys.exit(load\_entry\_point('certbot==1.31.0', 'console\_scripts', 'certbot')())  
File "/usr/local/bin/certbot", line 25, in importlib\_load\_entry\_point  
return next(matches).load()  
File "/usr/local/lib/python3.9/importlib/metadata.py", line 86, in load  
module = import\_module(match.group('module'))  
File "/usr/local/lib/python3.9/importlib/ **init**.py", line 127, in import\_module  
return \_bootstrap.\_gcd\_import(name[level:], package, level)  
File "", line 1030, in \_gcd\_import  
File "", line 1007, in \_find\_and\_load  
File "", line 986, in \_find\_and\_load\_unlocked  
File "", line 680, in \_load\_unlocked  
File "", line 850, in exec\_module  
File "", line 228, in \_call\_with\_frames\_removed  
File "/usr/local/lib/python3.9/site-packages/certbot/main.py", line 6, in   
from certbot.\_internal import main as internal\_main  
File "/usr/local/lib/python3.9/site-packages/certbot/\_internal/main.py", line 19, in   
import josepy as jose  
File "/usr/local/lib/python3.9/site-packages/josepy/ **init**.py", line 40, in   
from josepy.json\_util import (  
File "/usr/local/lib/python3.9/site-packages/josepy/json\_util.py", line 14, in   
from OpenSSL import crypto  
File "/usr/local/lib/python3.9/site-packages/OpenSSL/ **init**.py", line 8, in   
from OpenSSL import crypto, SSL  
File "/usr/local/lib/python3.9/site-packages/OpenSSL/crypto.py", line 14, in   
from cryptography import utils, x509  
File "/usr/local/lib/python3.9/site-packages/cryptography/x509/ **init**.py", line 6, in   
from cryptography.x509 import certificate\_transparency  
File "/usr/local/lib/python3.9/site-packages/cryptography/x509/certificate\_transparency.py", line 10, in   
from cryptography.hazmat.bindings.\_rust import x509 as rust\_x509  
ImportError: cannot import name 'x509' from 'cryptography.hazmat.bindings.\_rust' (unknown location)

How to fix?

---

<div class="post-metadata">

**Author:** ![Schamschula](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/schamschula/32/54056_2.png) [@Schamschula](https://community.letsencrypt.org/u/Schamschula)\
**Post date:** [October 10, 2022, 5:05pm UTC](https://community.letsencrypt.org/t/importerror-cannot-import-name-x509-from-cryptography-hazmat-bindings-rust/185882/2 "2022-10-10T17:05:09Z")

</div>

I just saw the same message under FreeBSD 13.1-RELEASE-p2.

It likely is an issue with a package certbot depends on.

---

<div class="post-metadata">

**Author:** ![Schamschula](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/schamschula/32/54056_2.png) [@Schamschula](https://community.letsencrypt.org/u/Schamschula)\
**Post date:** [October 10, 2022, 5:12pm UTC](https://community.letsencrypt.org/t/importerror-cannot-import-name-x509-from-cryptography-hazmat-bindings-rust/185882/3 "2022-10-10T17:12:02Z")

</div>

> [@bagas](#):
>
> ImportError: cannot import name 'x509' from 'cryptography.hazmat.bindings.\_rust' (unknown location)

It looks like `py-cryptography` was recently updated to version 38.0.1. This may not be backward compatible.

---

<div class="post-metadata">

**Author:** ![bagas](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/bagas/32/64649_2.png) [@bagas](https://community.letsencrypt.org/u/bagas)\
**Post date:** [October 10, 2022, 5:40pm UTC](https://community.letsencrypt.org/t/importerror-cannot-import-name-x509-from-cryptography-hazmat-bindings-rust/185882/4 "2022-10-10T17:40:48Z")

</div>

Hopefully the developers will fix the bug soon.

---

<div class="post-metadata">

**Author:** ![Schamschula](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/schamschula/32/54056_2.png) [@Schamschula](https://community.letsencrypt.org/u/Schamschula)\
**Post date:** [October 10, 2022, 5:51pm UTC](https://community.letsencrypt.org/t/importerror-cannot-import-name-x509-from-cryptography-hazmat-bindings-rust/185882/5 "2022-10-10T17:51:35Z")

</div>

See: [https://bugs.freebsd.org/bugzilla/show\_bug.cgi?id=266937](https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=266937)

---

<div class="post-metadata">

**Author:** ![Osiris](https://avatars.discourse-cdn.com/v4/letter/o/839c29/32.png) [@Osiris](https://community.letsencrypt.org/u/Osiris)\
**Post date:** [October 10, 2022, 7:01pm UTC](https://community.letsencrypt.org/t/importerror-cannot-import-name-x509-from-cryptography-hazmat-bindings-rust/185882/6 "2022-10-10T19:01:11Z")

</div>

The dependency on `cryptography.hazmat.bindings._rust.x509` was added [in `cryptography-35.0.0`](https://github.com/pyca/cryptography/commit/ae4ed8d4375a765f69cfc8e1bfbe4021655171f4).

However, [it seems FreeBSD compiles `cryptography` without the Rust modules](https://cgit.freebsd.org/ports/tree/security/py-cryptography/files/patch-setup.py?id=f5711e95bcd17b154bdd697cb3f1650a788fdf3c).

So ultimately this is, I think, a decision of the FreeBSD ports (?) team not wanting to use Rust, whereas that is not optional any longer. Back in 3.4.8 there was a `CRYPTOGRAPHY_DONT_BUILD_RUST` option, which has been removed from `cryptography` apparently. And the FreeBSD ports (?) team just hacked away further at the `setup.py` so it doesn't require Rust. Except that has grave consequences if a module requiring Rust is required elsewhere in `cryptography`, essentially breaking it.

I believe this is not isolated to Certbot by the way. Just running `from cryptography.x509 import certificate_transparency` in a Python shell should also return this error. (Or `from cryptography import x509` or simply `from OpenSSL import crypto` which ultimately import all the other stuff.)

You can probably get Certbot (and other applications depending on `cryptography.x509.certificate_transparency` and/or `cryptography.hazmat.bindings._rust`) working again by downgrading to `cryptography-3.4.8`.

And also the version of Certbot probably doesn't matter.

---

<div class="post-metadata">

**Author:** ![bagas](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/bagas/32/64649_2.png) [@bagas](https://community.letsencrypt.org/u/bagas)\
**Post date:** [October 11, 2022, 3:08pm UTC](https://community.letsencrypt.org/t/importerror-cannot-import-name-x509-from-cryptography-hazmat-bindings-rust/185882/7 "2022-10-11T15:08:08Z")

</div>

> [@Osiris](#):
>
> You can probably get Certbot (and other applications depending on `cryptography.x509.certificate_transparency` and/or `cryptography.hazmat.bindings._rust`) working again by downgrading to `cryptography-3.4.8`.
> 
> And also the version of Certbot probably doesn't matter.

What is rust for?  
Of the ports, it is difficult to assemble it on the server.  
Having fresh, fast hardware, it will take 30-40 minutes to assemble from rust ports.  
Pretty heavy for a server.

---

<div class="post-metadata">

**Author:** ![Osiris](https://avatars.discourse-cdn.com/v4/letter/o/839c29/32.png) [@Osiris](https://community.letsencrypt.org/u/Osiris)\
**Post date:** [October 11, 2022, 4:27pm UTC](https://community.letsencrypt.org/t/importerror-cannot-import-name-x509-from-cryptography-hazmat-bindings-rust/185882/8 "2022-10-11T16:27:31Z")

</div>

> [@bagas](#):
>
> What is rust for?

Often, Python modules require non-Python code for certain functions. Rust is a popular programming language for security sensitive code, as it has many benefits such as memory safety, something C(++) cannot guarantee from the language point of view. Cryptography has decided to use Rust for certain parts of the module.

> [@bagas](#):
>
> Of the ports, it is difficult to assemble it on the server.  
> Having fresh, fast hardware, it will take 30-40 minutes to assemble from rust ports.  
> Pretty heavy for a server.

You mean, to compile the Rust toolchain itself? Or cryptography parts requiring Rust?

---

<div class="post-metadata">

**Author:** ![bagas](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/bagas/32/64649_2.png) [@bagas](https://community.letsencrypt.org/u/bagas)\
**Post date:** [October 11, 2022, 5:13pm UTC](https://community.letsencrypt.org/t/importerror-cannot-import-name-x509-from-cryptography-hazmat-bindings-rust/185882/9 "2022-10-11T17:13:01Z")

</div>

> [@Osiris](#):
>
> You mean, to compile the Rust toolchain itself? Or cryptography parts requiring Rust?

lang/rust, it is assembled from ports for 30 minutes, while giving 100% load on the disk and processor.  
With Intel Xeon E-2136 processor and nvme drives.

---

<div class="post-metadata">

**Author:** ![Osiris](https://avatars.discourse-cdn.com/v4/letter/o/839c29/32.png) [@Osiris](https://community.letsencrypt.org/u/Osiris)\
**Post date:** [October 11, 2022, 5:20pm UTC](https://community.letsencrypt.org/t/importerror-cannot-import-name-x509-from-cryptography-hazmat-bindings-rust/185882/10 "2022-10-11T17:20:55Z")

</div>

I'm not surprised. But when you've got the toolchain installed, you can just leave it available for other packages too 🙂

---

<div class="post-metadata">

**Author:** ![bagas](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/bagas/32/64649_2.png) [@bagas](https://community.letsencrypt.org/u/bagas)\
**Post date:** [October 12, 2022, 5:48am UTC](https://community.letsencrypt.org/t/importerror-cannot-import-name-x509-from-cryptography-hazmat-bindings-rust/185882/11 "2022-10-12T05:48:45Z")

</div>

We decided to use security/acme.sh on new servers.  
On older servers, we will continue to use certbot for now.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/letsencrypt/original/3X/c/a/ca6c06ea1ea201324bba7048c6841ce60236468d.png) [@system](https://community.letsencrypt.org/u/system)\
**Post date:** [November 11, 2022, 6:59am UTC](https://community.letsencrypt.org/t/importerror-cannot-import-name-x509-from-cryptography-hazmat-bindings-rust/185882/13 "2022-11-11T06:59:50Z")

</div>

Closed on November 11, 2022, 6:59am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
