Python Forum

Full Version: How to do the same as python -m requests.certs inside script?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This might be a dumb question -

in the command line, python -m requests.cert gives result:
/etc/pki/tls/certs/ca-bundle.crt

How is the right way to get the result inside python script?
#!/usr/bin/env python
import requets

result=requests.cert
print(result)
The script above returns result:
Output:
<module 'requests.certs' from '/usr/lib/python2.7/dist-packages/requests/certs.pyc'>
not sure why it is like this. I would like to get /etc/pki/tls/certs/ca-bundle.crt
you have mispelled requests line 2
method name is certs, not cert line 4
Look at the source code of requests.certs.py you will see all it does is to import where() function from third-party package certifi

the rest of the code is within if __name__ == '__main__': block and executed when you execute crts.py as standalone script.
So if you want to replicate
from certifi import where
print(where())
the source of where()
import os


def where():
    f = os.path.dirname(__file__)

    return os.path.join(f, 'cacert.pem')
of course this assumes certiffi is installed