ssl.SSLCertVerificationError:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败:无法获取本地颁发者证书(_ssl.c:1108)

i2byvkas  于 2023-08-06  发布在  其他
关注(0)|答案(3)|浏览(183)

我试图运行一个简单的Python脚本来访问WINDOWS中minio服务器中的s3桶。服务器正在使用自签名证书。SSL握手中出现错误。我已经尝试了所有可能的方法来纠正它,但它仍然抛出错误。
我的python脚本from minio import Minio

from minio.error import (ResponseError, BucketAlreadyOwnedByYou,
                     BucketAlreadyExists)

def new():

minioClient = Minio('10.177.218.8:9000',access_key='minio_key',secret_key='password',secure=True)

buckets = minioClient.list_buckets();

for bucket in buckets:
    print(bucket.name, bucket.creation_date)

 new()

字符串
这是我得到的错误

File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3-1.25.8-               
 py3.8.egg\urllib3\connectionpool.py", line 665, in urlopen
httplib_response = self._make_request(
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3-1.25.8-     
py3.8.egg\urllib3\connectionpool.py", line 376, in _make_request
self._validate_conn(conn)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3-1.25.8- 
py3.8.egg\urllib3\connectionpool.py", line 994, in _validate_conn
conn.connect()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3-1.25.8- 
py3.8.egg\urllib3\connection.py", line 352, in connect
self.sock = ssl_wrap_socket(
 File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3-1.25.8- 
py3.8.egg\urllib3\util\ssl_.py", line 383, in ssl_wrap_socket
return context.wrap_socket(sock)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\ssl.py", line 1309, in 
 do_handshake
self._sslobj.do_handshake() 
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to 
get local issuer certificate (_ssl.c:1108)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Admin\Documents\S3\new.py", line 21, in <module>
new()
File "C:\Users\Admin\Documents\S3\new.py", line 11, in new
buckets = minioClient.list_buckets();
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\minio-5.0.9- 
py3.8.egg\minio\api.py", line 427, in list_buckets
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3-1.25.8- 
py3.8.egg\urllib3\poolmanager.py", line 330, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3-1.25.8- 
py3.8.egg\urllib3\connectionpool.py", line 747, in urlopen
 return self.urlopen(
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3-1.25.8- 
py3.8.egg\urllib3\connectionpool.py", line 747, in urlopen
return self.urlopen(
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3-1.25.8- 
py3.8.egg\urllib3\connectionpool.py", line 747, in urlopen
return self.urlopen(
[Previous line repeated 2 more times]
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3-1.25.8- 
py3.8.egg\urllib3\connectionpool.py", line 719, in urlopen
retries = retries.increment(
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3-1.25.8- 
py3.8.egg\urllib3\util\retry.py", line 436, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='10.177.218.8', port=9000): Max retries 
exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: 
CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate 
(_ssl.c:1108)')))


我也在受信任的存储中安装了证书。如何在Windows中解决这个问题?

ryevplcw

ryevplcw1#

通过执行以下操作,我终于能够在Windows上更正SSL VERIFY错误:
1.执行print(requests.certs.where())并复制完整的文件路径。
1.在脚本中创建一个如下所示的变量,并粘贴文件路径:
cafile = r'lib\site-packages\certifi\cacert.pem'
1.在verify设置为新变量的情况下执行请求:page = requests.get(URL_STRING, verify=cafile)

  • 尽可能不设置verify = False *

也许这也会保存其他一些SSL疲惫的灵魂。

bq9c1y66

bq9c1y662#

简单的解决方案,使用Minio自定义httpClient:

import urllib3

httpClient = urllib3.PoolManager()

minioClient = Minio(....,
                    .....
                    access_key=...,
                    secret_key=...,
                    http_client = httpClient)

字符串

ux6nzvsh

ux6nzvsh3#

我有一个Minio服务器在EKS上的Nginx入口后面运行,并启用了TLS。基于John的解决方案,这对我很有效:

  • 按照以下顺序从tls.crt和ca.crt创建一个cabundle.pem文件:
  • 中级CA证书2
  • 中级CA证书1
  • 根CA证书
  • 将cabundle传递到urllib3.PoolManager()配置:
http_client = urllib3.PoolManager(
    ca_certs = "cabundle.pem",
    cert_reqs="CERT_REQUIRED",
)
client = Minio(
    "localhost:9000",
    access_key="minioadmin",
    secret_key="secretpassword",
    http_client=http_client,
)

字符串

相关问题