italoseara / whatsappy

A whatsapp api made with selenium in Python
MIT License
43 stars 8 forks source link

Error while using the example code. #20

Closed tbdsilva closed 1 year ago

tbdsilva commented 1 year ago

Hello I tried to run the example code and it gave me the follow error:

% python wpp.py
Traceback (most recent call last): File "/Users/thyagosilva/Desktop/wpp.py", line 1, in from whatsappy import Whatsapp File "/usr/local/lib/python3.9/site-packages/whatsappy/init.py", line 1, in from .main import Whatsapp File "/usr/local/lib/python3.9/site-packages/whatsappy/main.py", line 590 match __name: ^ SyntaxError: invalid syntax

tbdsilva commented 1 year ago

By the way. I am running it on macbook.

tbdsilva commented 1 year ago

It worked on python 3.11

tbdsilva commented 1 year ago

Now i am getting this error:

python wpp.py Scan the QR code with your phone to log in. WhatsApp Web is ready! Exception in thread Thread-2 (_on_message): Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1038, in _bootstrap_inner self.run() File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 975, in run self._target(*self._args, **self._kwargs) File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/whatsappy/whatsapp.py", line 257, in _on_message last_check = self.unread_messages ^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/whatsappy/whatsapp.py", line 148, in unread_messages return [UnreadMessage(self, element) for element in self.driver.find_elements(By.XPATH, Selectors.UNREAD_CONVERSATIONS_XPATH)] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/whatsappy/whatsapp.py", line 148, in return [UnreadMessage(self, element) for element in self.driver.find_elements(By.XPATH, Selectors.UNREAD_CONVERSATIONS_XPATH)] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/whatsappy/messages/unread_message.py", line 39, in init self.message = _element.find_element(By.CSS_SELECTOR, Selectors.UNREAD_LAST_MESSAGE).get_attribute("title") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/selenium/webdriver/remote/webelement.py", line 417, in find_element return self._execute(Command.FIND_CHILD_ELEMENT, {"using": by, "value": value})["value"] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/selenium/webdriver/remote/webelement.py", line 395, in _execute return self._parent.execute(command, params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 346, in execute self.error_handler.check_response(response) File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: stale element not found (Session info: chrome=114.0.5735.198); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#stale-element-reference-exception Stacktrace: 0 chromedriver 0x000000010e5826b8 chromedriver + 4937400 1 chromedriver 0x000000010e579b73 chromedriver + 4901747 2 chromedriver 0x000000010e137616 chromedriver + 435734 3 chromedriver 0x000000010e13cadf chromedriver + 457439 4 chromedriver 0x000000010e13eb87 chromedriver + 465799 5 chromedriver 0x000000010e13ec8c chromedriver + 466060 6 chromedriver 0x000000010e17aa2b chromedriver + 711211 7 chromedriver 0x000000010e17b0a1 chromedriver + 712865 8 chromedriver 0x000000010e16eae6 chromedriver + 662246 9 chromedriver 0x000000010e19f03d chromedriver + 860221 10 chromedriver 0x000000010e16e9c1 chromedriver + 661953 11 chromedriver 0x000000010e19f1ce chromedriver + 860622 12 chromedriver 0x000000010e1b9e76 chromedriver + 970358 13 chromedriver 0x000000010e19ede3 chromedriver + 859619 14 chromedriver 0x000000010e16cd7f chromedriver + 654719 15 chromedriver 0x000000010e16e0de chromedriver + 659678 16 chromedriver 0x000000010e53e2ad chromedriver + 4657837 17 chromedriver 0x000000010e543130 chromedriver + 4677936 18 chromedriver 0x000000010e549def chromedriver + 4705775 19 chromedriver 0x000000010e54405a chromedriver + 4681818 20 chromedriver 0x000000010e51692c chromedriver + 4495660 21 chromedriver 0x000000010e561838 chromedriver + 4802616 22 chromedriver 0x000000010e5619b7 chromedriver + 4802999 23 chromedriver 0x000000010e57299f chromedriver + 4872607 24 libsystem_pthread.dylib 0x00007ff8015f74e1 _pthread_start + 125 25 libsystem_pthread.dylib 0x00007ff8015f2f6b thread_start + 15

tbdsilva commented 1 year ago

I had to put a time.sleep() to work.

italoseara commented 1 year ago

Hi, the first error is because it only works in Python 3.11. Thank you for showing the solution to the second error, I'll try to find a faster approach and implement it. I'll keep the issue open for now.

tbdsilva commented 1 year ago

Thanks Italo. I just sent you an email right now. If you have any time to read and reply i appreciate it! <3

anupammaurya6767 commented 10 months ago

I had to put a time.sleep() to work.

I had to put a time.sleep() to work.

where?

italoseara commented 10 months ago

I had to put a time.sleep() to work.

I had to put a time.sleep() to work.

where?

I don't know if the repository still works after the new update, I haven't been active in this repository in a while. I'll have to test it