Automatic E-Mail sender failed during testing

import time

from pynput.mouse import Button, Controller

from pynput.keyboard import Key, Controller

time.sleep(3.5)

Keyboard = Controller()

Mouse = Controller()

#Opens Edge browser

Mouse.position = (236, 870)

Mouse.press(Button.left)

Mouse.release(Button.left)

Mouse.position = (1049, 663)

Mouse.press(Button.left)

Mouse.release(Button.left)

time.sleep(4.5)

Mouse.position = (946, 495)

Mouse.press(Button.left)

Mouse.release(Button.left)

time.sleep(4.5)

Mouse.position = (747, 369)

Mouse.press(Button.left)

Mouse.release(Button.left)

time.sleep(1.5)

Mouse.position = (742, 455)

Mouse.press(Button.left)

Mouse.release(Button.left)

time.sleep(9.5)

Mouse.position = (97, 215)

Mouse.press(Button.left)

Mouse.release(Button.left)

time.sleep(3.5)

Keyboard.type("Can' tell")

Mouse.position = (1253, 420)

Mouse.press(Button.left)

Mouse.release(Button.left)

time.sleep(0.5)

Keyboard.type("Test E-Mail")

Mouse.position = (1094, 468)

Mouse.press(Button.left)

Mouse.release(Button.left)

time.sleep(0.5)

Keyboard.type("This is just a test E-Mail.")

#1006, 819

Mouse.position = (1006, 819)

Mouse.press(Button.left)

Mouse.release(Button.left)

time.sleep(0.5)

time.sleep(4.5)

print("Congratulations program successfully finished!")

This is a email sender made with pynput not using OS

I am still a beginner so I needed some help

This is the error that it is showing:

It says Button.left is the error but I have already declared the Mouse variable in a line

I honestly can’t understand what the error. Please help me

Please show us the error you got as text, not as a screenshot or photo.

You can’t use the same name for both the mouse controller and the keyboard controller.

You have:

from pynput.mouse import Button, Controller

which loads the mouse controller as the name “Controller”. Then the next line:

from pynput.keyboard import Key, Controller

overwrites the mouse controller with the keyboard controller. So when you run this:

Mouse = Controller()

you think you are getting a mouse controller called “Mouse”, but it is actually a keyboard controller called “Mouse”. So when you try to click with the keyboard:

Mouse.press(Button.left)

you get an internal pynput error.

You can get a hint that this is the error by reading the traceback, which shows that the error is coming from the pynput keyboard module, not the mouse module.

Solution:

Give at least one of the two different controllers a different name.

from pynput.keyboard import Key
from pynput.keyboard import Controller as KBController
1 Like

Thanks man you really helped me out. You even helped me out on the last post too. I am really thankful to you! I have been doing this project for like 1 week now. Thanks so much!