Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frequent KeyError: 'InvalidFromAddress' traceback messages despite working some of the time #10

Open
darmstrong8008 opened this issue Feb 23, 2024 · 1 comment

Comments

@darmstrong8008
Copy link

darmstrong8008 commented Feb 23, 2024

I have the following code snippet that works some of the time, but more often that not results in a traceback indicating KeyError: 'InvalidFromAddress'

I am using python 3.10

    def __notifySend(self, to_email: str, from_email: str) -> None: 
        msg = BasicMessage()
        slc = SocketLabsClient(
            int(str(os.getenv("SOCKETLABS_SERVER_ID"))),
            str(os.getenv("SOCKETLABS_API_KEY"))
        )
        msg.subject             = "Suspected troll found!"
        msg.html_body           = "<html>Busted!</html>"
        msg.plain_text_body     = "We got 'im boys!"
        msg.from_email_address  = EmailAddress(from_email)
        msg.to_email_address.append(EmailAddress(to_email))

        response = slc.send(msg)
        print(response)
        return

I am not sure why this would be the case, as the method more or less follows exactly what the documentation suggests, and sometimes it works as expected. I have tested this on two separate known-good email addresses and can confirm that when the code does what it is supposed to, they appear in my inbox as expected.

@darmstrong8008
Copy link
Author

...
failed attempt, trying again...
failed attempt, trying again...
failed attempt, trying again...
failed attempt, trying again...
failed attempt, trying again...
failed attempt, trying again...
failed attempt, trying again...
failed attempt, trying again...
failed attempt, trying again...
failed attempt, trying again...
failed attempt, trying again...
failed attempt, trying again...
failed attempt, trying again...
failed attempt, trying again...
failed attempt, trying again...
failed attempt, trying again...
failed attempt, trying again...
failed attempt, trying again...
failed attempt, trying again...
failed attempt, trying again...
Successful send of message: Successful send of message

^ From the same code snippet modified with:

        while True:
            try:
                response = slc.send(msg)
                print(response)
                break
            except KeyError:
                print("failed attempt, trying again...")
                time.sleep(4)
                continue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant