简体   繁体   English

SSL:CERTIFICATE_VERIFY_FAILED 使用预训练检测器 2 model 时

[英]SSL: CERTIFICATE_VERIFY_FAILED when using pretrained detectron2 model

I am trying to just use the pretrained mask_rcnn_R_50_FPN_3x model in detectron2 on an image.我试图在图像上的detectron2中使用预训练的mask_rcnn_R_50_FPN_3x detectron2 I get the error ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1131) .我收到错误ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1131)

I am using Windows Subsystem for Linux.我正在使用 Linux 的 Windows 子系统。 The following code produces the error.以下代码会产生错误。

from detectron2.config import get_cfg
from detectron2 import model_zoo
from detectron2.engine import DefaultPredictor

cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
cfg.MODEL.DEVICE='cpu'

predictor = DefaultPredictor(cfg)

I've tried updating the certifi package.我已经尝试更新certifi
I've tried我试过了

sudo apt install ca-certificates
sudo update-ca-certificates --fresh
export SSL_CERT_DIR=/etc/ssl/certs

based on one of the answers here: https://stackoverflow.com/questions/52805115/certificate-verify-failed-unable-to-get-local-issuer-certificate.\ I've tried downloading the certificates for https://dl.fbaipublicfiles.com (by, in Google Chrome, clicking the padlock symbol -> 'Connection is secure' -> 'Certificate is valid' -> 'Details' -> 'Copy to file', and then doing the same thing for the different certificates under the 'Certification Path' tab) and copying their contents into the cacert.pem file.基于此处的答案之一: https://stackoverflow.com/questions/52805115/certificate-verify-failed-unable-to-get-local-issuer-certificate。\我尝试下载Z5E056C500A1C4B6A7110B50D807BADEZ5 的证书: /dl.fbaipublicfiles.com (在谷歌浏览器中,单击挂锁符号 -> '连接安全' -> '证书有效' -> '详细信息' -> '复制到文件',然后做同样的事情对于“证书路径”选项卡下的不同证书)并将其内容复制到cacert.pem文件中。


UPDATE:更新:
It seems to have something to do with the urllib.request module (altough I might be misunderstanding things).它似乎与urllib.request模块有关(尽管我可能会误解一些事情)。 I have found that我发现

from urllib import request
request.urlretrieve('https://dl.fbaipublicfiles.com')

(the urlretrive function is called by detectron2 ) results in the same error, whereas urlretrive function 由detectron2调用)导致相同的错误,而

import requests
requests.get('https://dl.fbaipublicfiles.com')

works fine.工作正常。

Try to put this after your import statements:尝试将其放在您的import语句之后:

import certifi
import ssl

def create_context():
    context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
    context.load_verify_locations(certifi.where())
    return context
ssl._create_default_https_context = create_context

This tells urllib to use certifi 's certificates.这告诉urllib使用certifi的证书。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Python3中使用请求时,SSL:CERTIFICATE_VERIFY_FAILED - SSL: CERTIFICATE_VERIFY_FAILED when using Requests in Python3 使用 Docker 时,SSL 错误 CERTIFICATE_VERIFY_FAILED 与 Locust - SSL error CERTIFICATE_VERIFY_FAILED with Locust when using Docker 如何解决[SSL: CERTIFICATE_VERIFY_FAILED] 在不绕过SSL 验证的情况下使用urllib 时出错 - How to Solve [SSL: CERTIFICATE_VERIFY_FAILED] Error when Using urllib without bypassing SSL verification SSL:策展人访问 elasticsearch 时出现 CERTIFICATE_VERIFY_FAILED 错误 - SSL: CERTIFICATE_VERIFY_FAILED error when curator access elasticsearch 使用 PIP 时出现“SSL:CERTIFICATE_VERIFY_FAILED”错误 - "SSL: CERTIFICATE_VERIFY_FAILED" error while using PIP SSL:CERTIFICATE_VERIFY_FAILED 使用 Watson Streaming STT - SSL: CERTIFICATE_VERIFY_FAILED using Watson Streaming STT SSL:将数据加载到 seaborn 时出现 CERTIFICATE_VERIFY_FAILED 错误? - SSL: CERTIFICATE_VERIFY_FAILED error when loading data into seaborn? 使用urllib3时,在Windows 10上克服SSL:CERTIFICATE_VERIFY_FAILED - Overcoming SSL: CERTIFICATE_VERIFY_FAILED on Windows 10 when using urllib3 使用python下载jpg时出现错误,导致:[SSL:CERTIFICATE_VERIFY_FAILED] - Error when downloading jpg using python result in: [SSL: CERTIFICATE_VERIFY_FAILED] 龙卷风:[SSL:CERTIFICATE_VERIFY_FAILED] - Tornado : [SSL: CERTIFICATE_VERIFY_FAILED]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM