Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python ssl module
#1
If I open Idle, I can import the module ssl no problem

But

Quote:pip list

in bash shows no module ssl

Why does ssl not show up in the list, but can be imported without an error message?

After importing ssl in Idle, this command

print(ssl.__version__)
just shows:

Output:
Traceback (most recent call last): File "/usr/lib/python3.10/idlelib/run.py", line 578, in runcode exec(code, self.locals) File "<pyshell#31>", line 1, in <module> AttributeError: module 'ssl' has no attribute '__version__'
I want to know what version of module ssl I have and if it can be updated, because I have an error when trying to send an email using Python via gmail. Sending via QQ everything works:

Quote:pedro@pedro-HP:~/babystuff/forAgro/python$ ./send_1_email_via_Pilar_gmail_no_attachment_V1.py
sender is [email protected] ...
Traceback (most recent call last):
File "/home/pedro/babystuff/forAgro/python/./send_1_email_via_Pilar_gmail_no_attachment_V1.py", line 136, in <module>
server = smtplib.SMTP_SSL(smtp_server, port, context=context)
File "/usr/lib/python3.10/smtplib.py", line 1050, in __init__
SMTP.__init__(self, host, port, local_hostname, timeout,
File "/usr/lib/python3.10/smtplib.py", line 255, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python3.10/smtplib.py", line 341, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python3.10/smtplib.py", line 1057, in _get_socket
new_socket = self.context.wrap_socket(new_socket,
File "/usr/lib/python3.10/ssl.py", line 513, in wrap_socket
return self.sslsocket_class._create(
File "/usr/lib/python3.10/ssl.py", line 1100, in _create
self.do_handshake()
File "/usr/lib/python3.10/ssl.py", line 1371, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError:[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1007)
pedro@pedro-HP:~/babystuff/forAgro/python$

I thought I could just run pip install ssl

If the version I have is the latest, I usually just get a message to that effect.

But pip tries to get and unpack a .tar.gz file, and that has a problem, which I have shortened here:

Quote:pedro@pedro-HP:~/babystuff/forAgro/python$ pip3 install ssl
Defaulting to user installation because normal site-packages is not writeable
Collecting ssl
Downloading ssl-1.16.tar.gz (33 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py egg_info did not run successfully.
│ exit code: 1

..................

note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Very grateful for any tips or advice!
Reply
#2
for version number:

>>> print(ssl.OPENSSL_VERSION)
>>> 'OpenSSL 3.0.2 15 Mar 2022'
to get a List of all ssl commands:
>>> import ssl
>>> xx = dir(ssl)
>>> for item in xx:
...    print(item)
...
Pedroski55 likes this post
Reply
#3
Thanks!

I get:

Output:
print(ssl.OPENSSL_VERSION) OpenSSL 3.0.2 15 Mar 2022
Doesn't seem so old!
Reply
#4
see: https://docs.python.org/3/library/ssl.html
It looks like a lot of waht was in 3.10 has been depreciated.
Reply
#5
The morning always brings light!

Trying again with gmail again, I changed to port 587 and used: server.starttls(context=context)

context = ssl.create_default_context()
server = smtplib.SMTP(smtp_server, port)
server.starttls(context=context)
server.login(sender_email, password)
For this kind of login you need an app password. When I removed the spaces from the app password, I also deleted 1 letter, so it was wrong!

You don't need to remove the spaces from the app password either!!

Now this works smoothly with gmail, yahoo and QQ, straight from bash!

I wonder if the gf will be happy??
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020