PyNetBox API是否可以选择验证自签名证书的CA证书? [英] Does PyNetBox API have an option to verify CA cert for Self Signed Cert?

查看:152
本文介绍了PyNetBox API是否可以选择验证自签名证书的CA证书?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将NetBox Ansible模块与具有自签名证书的NetBox安装一起使用. [1]但是,这给了我错误:

I've been trying to play around with NetBox Ansible modules with a NetBox setup having self signed certificate. [1] That however gives me the error:

无法建立与Netbox API的连接

我意识到这是由于我使用了自签名证书:

I realised that this was due to me using Self signed certificate:

>>> 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"

I was wondering if there is a way to specify cacert file with pynetbox, the same way we do with requests using 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] 使用Netbox Ansible模块

Python版本:Python 3.7.7 pynetbox版本:"2.8"

Python Version: Python 3.7.7 pynetbox version: '2.8'

推荐答案

This was discussed in 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

这篇关于PyNetBox API是否可以选择验证自签名证书的CA证书?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆