I am trying to run simple emailsender.py script on repl.it to send an email. It works without any problem when I try to run it on desktop PC, but on repl.it I am having an error message OSError: [Errno 99] Cannot assign requested address as detailed below. The emailsender.py program looks like this:

import smtplib def send_email(username: str, key: str): reciever = username+"@theirmail.cz" sender = "[email protected]" topic = "Autothorization bot" # header msg = "From: %s\r\nSubject: %s\r\nTo: %s\r\n\r\n" % (sender, topic, reciever) # add message content content = "Your key is: " + key msg += content server = smtplib.SMTP('smtp.seznam.cz') server.login('[email protected]', "my_email_password") server.sendmail(sender, reciever, msg) server.quit() 

When I try to run the script via python on repl.it, I get this error message after some time:

>>> import emailsender >>> emailsender.send_email("username", "test_message") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/runner/botpy/emailsender.py", line 24, in send_email server = smtplib.SMTP('smtp.seznam.cz') File "/usr/lib/python3.8/smtplib.py", line 253, in __init__ (code, msg) = self.connect(host, port) File "/usr/lib/python3.8/smtplib.py", line 337, in connect self.sock = self._get_socket(host, port, self.timeout) File "/usr/lib/python3.8/smtplib.py", line 308, in _get_socket return socket.create_connection((host, port), timeout, File "/usr/lib/python3.8/socket.py", line 808, in create_connection raise err File "/usr/lib/python3.8/socket.py", line 796, in create_connection sock.connect(sa) OSError: [Errno 99] Cannot assign requested address 

This .py script is a piece of larger discord.py bot that I am trying to host on repl.it, but this should not have any effect, because this script alone is running well individually on desktop PC.

I've tried my best to figure out the cause of this error, but with no success so far.

2 Answers

For reasons unknown to me, a small configuration of commands fixed it.

New part of the script for sending the email looks like this:

server = smtplib.SMTP('smtp.seznam.cz', 587) server.starttls() server.ehlo() server.login('[email protected]', "my_email_password") server.sendmail(sender, reciever, msg) server.quit() 
1

I had the same error and port=587 fixed the problem

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.