0

I have this little bit of code that I copy and posted from one pycharm project file to another:

import ssl
import socket
from pprint import pprint

if __name__ == '__main__':
    cert = ssl.get_server_certificate(("www.example.com", 443))
    pprint(cert)

It works in the original file, but throws an AttributeError error in the new file. I am clueless as to why. Can anyone help? I tried two different virtualenvs with the same results. Here is a paste of my console output using one of them:

    $ workon sslchecker
    (sslchecker) $ python /path/to/original/main.py
    ('-----BEGIN CERTIFICATE-----\n'
    ...
    '-----END CERTIFICATE-----\n')
    (sslchecker) $ python ~/path/to/copied/ssl.py
    Traceback (most recent call last):
      File "/path/to/copied/code.py", line 6, in <module>
        cert = ssl.get_server_certificate(("www.example.com", 443))
    AttributeError: module 'ssl' has no attribute 'get_server_certificate'
Andrew Schmitt
  • 135
  • 2
  • 7

0 Answers0