Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5390

Beginners • ssl.SSLError: [SSL: WRONG_VER..... (_ssl.c:992)

$
0
0
Hi,

I've been following a youtube tutorial for sending emails with attachments and I get this error when I run it:

Code:

ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:992)
anyone know what's going on with this? I'm confident I have all email, password, port and server details correct.

Code:

import smtplibfrom email.mime.multipart import MIMEMultipartfrom email.mime.text import MIMETextfrom email.mime.application import MIMEApplicationsubject = "Times file"body = "Times.txt attached"sender_email = 'xxxxxxxxxi@gmail.com'recipient_email = "dxxxxxxxx@gmail.com"sender_password = 'txxxxxxxxxxxxxxxt'smtp_server = 'smtp.gmail.com'smtp_port = 587path_to_file = '/home/pi/Times.txt'message = MIMEMultipart()message['Subject'] = subjectmessage['From'] = sender_emailmessage['To'] =recipient_emailbody_part = MIMEText(body)message.attach(body_part)with open(path_to_file,'rb') as file:    message.attach(MIMEApplication(file.read(),Name='Times.txt'))with smtplib.SMTP_SSL(smtp_server, smtp_port) as server:    server.login(sender_email, sender_password)    server.sendmail(sender_email, recipient_email, message.as_string())print("Email sent")
I ran a trace and go the folowing.

Code:

Traceback (most recent call last):  File "/home/pi/Documents/VMemail3.py", line 25, in <module>    with smtplib.SMTP_SSL(smtp_server, smtp_port) as server:         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/usr/lib/python3.11/smtplib.py", line 1050, in __init__    SMTP.__init__(self, host, port, local_hostname, timeout,  File "/usr/lib/python3.11/smtplib.py", line 255, in __init__    (code, msg) = self.connect(host, port)                  ^^^^^^^^^^^^^^^^^^^^^^^^  File "/usr/lib/python3.11/smtplib.py", line 341, in connect    self.sock = self._get_socket(host, port, self.timeout)                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/usr/lib/python3.11/smtplib.py", line 1057, in _get_socket    new_socket = self.context.wrap_socket(new_socket,                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/usr/lib/python3.11/ssl.py", line 517, in wrap_socket    return self.sslsocket_class._create(           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/usr/lib/python3.11/ssl.py", line 1108, in _create    self.do_handshake()  File "/usr/lib/python3.11/ssl.py", line 1379, in do_handshake    self._sslobj.do_handshake()ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:992)

Statistics: Posted by Splint — Sat Dec 14, 2024 6:48 am — Replies 1 — Views 28



Viewing all articles
Browse latest Browse all 5390

Latest Images

Trending Articles



Latest Images