Skip to content

Instantly share code, notes, and snippets.

@anseljh
Created September 21, 2018 18:46
Show Gist options
  • Save anseljh/74b442de518f189dbe4a5fa39940fed2 to your computer and use it in GitHub Desktop.
Save anseljh/74b442de518f189dbe4a5fa39940fed2 to your computer and use it in GitHub Desktop.

Code:

from os import environ
import certifi

def print_env():
    print(f"REQUESTS_CA_CERT is {environ.get('REQUESTS_CA_CERT')}")

def set_env():
    cafile = certifi.where()
    print(f"CA file is {cafile}")
    environ['REQUESTS_CA_CERT'] = cafile
    print("set_env() done!")

def download():
    import nltk
    print("About to call nltk.download()!")
    nltk.download()

if __name__ == '__main__':
    print_env()
    set_env()
    print_env()
    download()

Output:

pipenv run python extras/check_ssl.py 
Loading .env environment variables…
REQUESTS_CA_CERT is None
CA file is /Users/anseljh/.local/share/virtualenvs/project-name-s7XLw6jn/lib/python3.6/site-packages/certifi/cacert.pem
set_env() done!
REQUESTS_CA_CERT is /Users/anseljh/.local/share/virtualenvs/project-name-s7XLw6jn/lib/python3.6/site-packages/certifi/cacert.pem
About to call nltk.download()!
showing info https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/index.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment