在线资源有两个容易遗忘的事:域名续签、证书续签。域名还能收到注册商发来的提醒,但那个免费的证书颁发商似乎就没有这个贴心服务了。周初一咬牙,心说让 AI 帮忙写个例行巡检的脚本得了,给它几个网站地址,隔一天定时访问一下,看看访问结果,要是证书即将过期的话,也提示一下。
脚本很快就写完了,但是解析证书以获取过期时间的地方,它依赖了 OpenSSL 模块,一跑就报错。我当初看到脚本的时候,直觉以为代码里的 OpenSSL 就是系统内的 Open SSL 呢,这一下才想到不对,应该是需要 Python 封装过的,查了一下,是个叫 pyOpenSSL 的东东,用 pip3 执行了安装。再执行脚本,还报错:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Traceback (most recent call last): File "sslcerts.py", line 6, in <module> from OpenSSL import crypto File "/usr/lib/python3/dist-packages/OpenSSL/__init__.py", line 8, in <module> from OpenSSL import crypto, SSL File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 12, in <module> from cryptography import x509 File "/usr/lib/python3/dist-packages/cryptography/x509/__init__.py", line 8, in <module> from cryptography.x509.base import ( File "/usr/lib/python3/dist-packages/cryptography/x509/base.py", line 16, in <module> from cryptography.x509.extensions import Extension, ExtensionType File "/usr/lib/python3/dist-packages/cryptography/x509/extensions.py", line 18, in <module> from cryptography.hazmat.primitives import constant_time, serialization File "/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/constant_time.py", line 9, in <module> from cryptography.hazmat.bindings._constant_time import lib ModuleNotFoundError: No module named '_cffi_backend' |
虽说对 Python 不熟,从最后一行也能感觉到是 cffi 缺了。连忙 pip3 install cffi,又错:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
Building wheels for collected packages: cffi Running setup.py bdist_wheel for cffi ... error Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-l47kwr_n/cffi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpv8w_dl6spip-wheel- --python-tag cp37: running bdist_wheel running build running build_py creating build creating build/lib.linux-x86_64-3.7 creating build/lib.linux-x86_64-3.7/cffi copying cffi/__init__.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/api.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/backend_ctypes.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/cffi_opcode.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/commontypes.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/cparser.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/error.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/lock.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/model.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/pkgconfig.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/recompiler.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/setuptools_ext.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/vengine_cpy.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/vengine_gen.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/verifier.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/_cffi_include.h -> build/lib.linux-x86_64-3.7/cffi copying cffi/parse_c_type.h -> build/lib.linux-x86_64-3.7/cffi copying cffi/_embedding.h -> build/lib.linux-x86_64-3.7/cffi copying cffi/_cffi_errors.h -> build/lib.linux-x86_64-3.7/cffi running build_ext building '_cffi_backend' extension creating build/temp.linux-x86_64-3.7 creating build/temp.linux-x86_64-3.7/c x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DFFI_BUILDING=1 -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python3.7m -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.7/c/_cffi_backend.o c/_cffi_backend.c:2:10: fatal error: Python.h: No such file or directory #include <Python.h> ^~~~~~~~~~ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 ---------------------------------------- Failed building wheel for cffi Running setup.py clean for cffi Failed to build cffi Installing collected packages: pycparser, cffi Running setup.py install for cffi ... error Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-l47kwr_n/cffi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-8j375ypd-record/install-record.txt --single-version-externally-managed --compile --user --prefix=: running install running build running build_py creating build creating build/lib.linux-x86_64-3.7 creating build/lib.linux-x86_64-3.7/cffi copying cffi/__init__.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/api.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/backend_ctypes.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/cffi_opcode.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/commontypes.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/cparser.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/error.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/lock.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/model.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/pkgconfig.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/recompiler.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/setuptools_ext.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/vengine_cpy.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/vengine_gen.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/verifier.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/_cffi_include.h -> build/lib.linux-x86_64-3.7/cffi copying cffi/parse_c_type.h -> build/lib.linux-x86_64-3.7/cffi copying cffi/_embedding.h -> build/lib.linux-x86_64-3.7/cffi copying cffi/_cffi_errors.h -> build/lib.linux-x86_64-3.7/cffi running build_ext building '_cffi_backend' extension creating build/temp.linux-x86_64-3.7 creating build/temp.linux-x86_64-3.7/c x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DFFI_BUILDING=1 -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python3.7m -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.7/c/_cffi_backend.o c/_cffi_backend.c:2:10: fatal error: Python.h: No such file or directory #include <Python.h> ^~~~~~~~~~ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 ---------------------------------------- Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-l47kwr_n/cffi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-8j375ypd-record/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-build-l47kwr_n/cffi/ |
找不到 Python.h?老夫自己手动 find / -iname 'Python.h' 找了下,发现在 /usr/include/python3.6m 里有,图快,就执行了个 export CPPFLAGS=-I/usr/include/python3.6m 然后再安装 cffi。结果又出来这个,
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
Collecting cffi Using cached https://files.pythonhosted.org/packages/2b/a8/050ab4f0c3d4c1b8aaa805f70e26e84d0e27004907c5b8ecc1d31815f92a/cffi-1.15.1.tar.gz Collecting pycparser (from cffi) Using cached https://files.pythonhosted.org/packages/62/d5/5f610ebe421e85889f2e55e33b7f9a6795bd982198517d912eb1c76e1a53/pycparser-2.21-py2.py3-none-any.whl Building wheels for collected packages: cffi Running setup.py bdist_wheel for cffi ... error Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-7upd_psi/cffi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpz1y1qzwjpip-wheel- --python-tag cp37: running bdist_wheel running build running build_py creating build creating build/lib.linux-x86_64-3.7 creating build/lib.linux-x86_64-3.7/cffi copying cffi/__init__.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/api.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/backend_ctypes.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/cffi_opcode.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/commontypes.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/cparser.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/error.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/lock.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/model.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/pkgconfig.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/recompiler.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/setuptools_ext.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/vengine_cpy.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/vengine_gen.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/verifier.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/_cffi_include.h -> build/lib.linux-x86_64-3.7/cffi copying cffi/parse_c_type.h -> build/lib.linux-x86_64-3.7/cffi copying cffi/_embedding.h -> build/lib.linux-x86_64-3.7/cffi copying cffi/_cffi_errors.h -> build/lib.linux-x86_64-3.7/cffi running build_ext building '_cffi_backend' extension creating build/temp.linux-x86_64-3.7 creating build/temp.linux-x86_64-3.7/c x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -I/usr/include/python3.6m/ -fPIC -DFFI_BUILDING=1 -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python3.7m -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.7/c/_cffi_backend.o c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory #include <ffi.h> ^~~~~~~ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 ---------------------------------------- Failed building wheel for cffi Running setup.py clean for cffi Failed to build cffi Installing collected packages: pycparser, cffi Running setup.py install for cffi ... error Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-7upd_psi/cffi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-y_vdcnlb-record/install-record.txt --single-version-externally-managed --compile --user --prefix=: running install running build running build_py creating build creating build/lib.linux-x86_64-3.7 creating build/lib.linux-x86_64-3.7/cffi copying cffi/__init__.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/api.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/backend_ctypes.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/cffi_opcode.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/commontypes.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/cparser.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/error.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/lock.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/model.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/pkgconfig.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/recompiler.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/setuptools_ext.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/vengine_cpy.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/vengine_gen.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/verifier.py -> build/lib.linux-x86_64-3.7/cffi copying cffi/_cffi_include.h -> build/lib.linux-x86_64-3.7/cffi copying cffi/parse_c_type.h -> build/lib.linux-x86_64-3.7/cffi copying cffi/_embedding.h -> build/lib.linux-x86_64-3.7/cffi copying cffi/_cffi_errors.h -> build/lib.linux-x86_64-3.7/cffi running build_ext building '_cffi_backend' extension creating build/temp.linux-x86_64-3.7 creating build/temp.linux-x86_64-3.7/c x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -I/usr/include/python3.6m/ -fPIC -DFFI_BUILDING=1 -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python3.7m -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.7/c/_cffi_backend.o c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory #include <ffi.h> ^~~~~~~ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 ---------------------------------------- Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-7upd_psi/cffi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-y_vdcnlb-record/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-build-7upd_psi/cffi/ |
只好又 apt install libffi-dev 完了再试,终于把 cffi 装上了。
尝试执行脚本,仍错,
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Traceback (most recent call last): File "sslcerts.py", line 6, in <module> from OpenSSL import crypto File "/usr/lib/python3/dist-packages/OpenSSL/__init__.py", line 8, in <module> from OpenSSL import crypto, SSL File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 12, in <module> from cryptography import x509 File "/usr/lib/python3/dist-packages/cryptography/x509/__init__.py", line 8, in <module> from cryptography.x509.base import ( File "/usr/lib/python3/dist-packages/cryptography/x509/base.py", line 16, in <module> from cryptography.x509.extensions import Extension, ExtensionType File "/usr/lib/python3/dist-packages/cryptography/x509/extensions.py", line 18, in <module> from cryptography.hazmat.primitives import constant_time, serialization File "/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/constant_time.py", line 9, in <module> from cryptography.hazmat.bindings._constant_time import lib ImportError: this module was compiled for Python 3.6 |
唉,早知道不图快了。既然 3.6 的 python-dev 跟 python 版本不匹配,那它就没有用了,卸载掉,用 apt 命令安装 python3.7-dev。接着把 cffi 也卸载,然后重装,还要记得重装时要写成 pip3 --no-cache-dir install cffi,否则会直接把缓存里的、也就是刚刚卸载掉的版本用上。
这样折腾下来,脚本总算执行通过。
