PyNetBox API 是否可以选择验证自签名证书的 CA 证书?

Does PyNetBox API have an option to verify CA cert for Self Signed Cert?

我一直在尝试使用具有自签名证书的 NetBox 设置来使用 NetBox Ansible 模块。 [1] 然而,这给了我错误:

未能建立与 Netbox 的连接API

我意识到这是因为我使用了自签名证书:

>>> import pynetbox
>>> nb = pynetbox.api(
... 'https://netbox.url',
... token='XXX'
... )
 
>>> nb.dcim.devices.all()
 
<snipped>
 
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='netbox.url', port=443): Max retries exceeded with url: /api/dcim/devices/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)')))

我想知道是否有一种方法可以使用 pynetbox 指定 cacert 文件,就像我们使用 verify="/my/path/to/cacert.crt"

处理请求一样
>>> nb = pynetbox.api(
... 'https://netbox.url',
... token='XXX',
... private_key_file='/my/path/to/key',
... ssl_verify='/my/path/to/cacert.crt'
... )
Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
TypeError: __init__() got an unexpected keyword argument 'ssl_verify'

[1]

Python版本:Python3.7.7 pynetbox 版本:'2.8'

这在 an issue in their GitHub repo where they allege one can set the REQUESTS_CA_BUNDLE environment variable to point to the CA bundle that requests should use for verifying the endpoint (here are the requests docs)

中讨论过

理论上:

import pynetbox
import os

os.environ['REQUESTS_CA_BUNDLE'] = '/path/to/your/ca.pem'
# and off to the races

您可以像这样禁用 ssl 验证:

nb.http_session.verify = False

这里的文档中提到了它 https://buildmedia.readthedocs.org/media/pdf/pynetbox/latest/pynetbox.pdf