Skip to content

Instantly share code, notes, and snippets.

@afraz-khan
Created February 5, 2025 16:04
Show Gist options
  • Save afraz-khan/92c30db85c2226b01e6019c1c7c6ed12 to your computer and use it in GitHub Desktop.
Save afraz-khan/92c30db85c2226b01e6019c1c7c6ed12 to your computer and use it in GitHub Desktop.
Disable SSL Certificates verification in Python

Developers often encounter SSL certificate verification errors in Python when connecting to HTTPS endpoints. This can be frustrating, especially during local development. You can temporarily disable SSL certificate verification using the code below—just place it before the HTTPS connection in your script.

import ssl

try:
    _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
    # Legacy Python that doesn't verify HTTPS certificates by default
    pass
else:
    # Handle target environment that doesn't support HTTPS verification
    ssl._create_default_https_context = _create_unverified_https_context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment