<p dir="ltr"><br>
On 9 Sep 2014 04:00, "Barry Warsaw" <<a href="mailto:barry@python.org">barry@python.org</a>> wrote:<br>
> ><br>
> >This would need to be updated first, once it *did* take such an argument,<br>
> >this would be accomplished by:<br>
> ><br>
> >context = ssl.create_default_context()<br>
> >context.verify_mode = CERT_OPTIONACERT_NONE<br>
> >context.verify_hostname = False<br>
> >urllib.request.urlopen("<a href="https://something-i-apparently-dont-care-much-about">https://something-i-apparently-dont-care-much-about</a>",<br>
> >context=context)<br>
><br>
> There's probably an ugly hack possibility that uses unittest.mock.patch. ;)</p>
<p dir="ltr">We could actually make it an "official" hack:</p>
<p dir="ltr">    import urllib.request<br>
    urllib.request.urlopen = urllib.request._unverified_urlopen</p>
<p dir="ltr">Or else the user can just change the code to call the unverified one directly.</p>
<p dir="ltr">All we'd have to do is keep the existing version that doesn't validate certs properly around under the name "_unverified_urlopen".</p>
<p dir="ltr">I like this for a few reasons:</p>
<p dir="ltr">1. It doesn't get much easier than calling function A instead of function B<br>
2. Monkeypatching lets you do a process global hack <br>
3. The name tells you exactly why this is a bad idea<br>
4. It's easy to grep for later after you fix your certs<br>
5. The leading underscore acts as a strong "keep away" signal<br>
6. The leading underscore makes it clear this function may not always be available (e.g. Jython, older versions of Python)</p>
<p dir="ltr">Cheers,<br>
Nick.</p>
<p dir="ltr">><br>
> -Barry<br>
> _______________________________________________<br>
> Python-Dev mailing list<br>
> <a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/python-dev">https://mail.python.org/mailman/listinfo/python-dev</a><br>
> Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com">https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com</a><br>
</p>