0

While using detectron2 I've ran into SSL issues. However, it seems the SSL issues are related to python as they don't appear while using wget.

I can't use detectron2 to download the weights file https://dl.fbaipublicfiles.com/detectron2/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl:

from detectron2.config import get_cfg
from detectron2.engine import DefaultTrainer

cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")

default_trainer = DefaultTrainer(cfg)

The above detectron2 code gives the following error:

URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1091)>

I tried using requests which also didn't work:

import requests
response = requests.get('https://dl.fbaipublicfiles.com/detectron2/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl')

I can use wget to download the file:

wget https://dl.fbaipublicfiles.com/detectron2/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl

How can I setup python to use the same SSL certificates that wget is using?

MT0
  • 143,790
  • 11
  • 59
  • 117
user3731622
  • 4,844
  • 8
  • 45
  • 84
  • 1
    `requests` should bring in `certifi` which has root certs in it, probably roughly the same as what `wget` is using. Detectron has had some flakiness with their whole files downloading, so for your requests code, what if you tried to add `verify=False` to your request for an experiment? – wkl Sep 01 '22 at 19:24
  • @wkl using verify=False as argument to `requests.get` does work. I should've mentioned I tried that. However, I want to use SSL verification. I think you're right that `requests` uses `certifi`, but it seems like whatever is done is using different certs than `wget` and `wget` works. Re detectron flakiness, I heard about that. But I don't think what would explain why this case since `wget` works, but I could be wrong. – user3731622 Sep 01 '22 at 20:53
  • 1
    Detectron’s files are served by multiple hosts on the backend so this could be a matter of poor configuration on some of them, and your requests are sometimes assigned to a bad server. Notice that the error is complaining about a self signed cert which would indicate that one of their servers is using a self signed cert, and in that case you’d have to ignore verification, using different trusted certs wouldn’t matter. If this continues to be an issue, file a bug with the GitHub project. – wkl Sep 01 '22 at 21:07
  • Re "sometimes assigned to a bad server", I've been using detectron2 on a different computer and haven't seen this SSL issue. If the problem was really sometimes requests being routed to a bad server, wouldn't I see this on both computers I use? Also, wouldn't I see the problem with wget somtimes too? – user3731622 Sep 01 '22 at 21:47

1 Answers1

0

I did run following testing using urllib.request which is part of standard library

import urllib.request
import ssl
with urllib.request.urlopen('https://dl.fbaipublicfiles.com/detectron2/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl',context=ssl.SSLContext()) as f:
    content = f.read()

after that content is bytes object, no error or warning did appear during that. Please try running above code and write what is result in your case.

Daweo
  • 31,313
  • 3
  • 12
  • 25