Closed Jeck-Liu-Create closed 6 months ago
what's WPP_Whatsapp Version
WPP_Whatsapp Version is 0.1.5.2
try
pip install git+https://github.com/3mora2/WPP_Whatsapp
Still can't be used normally
C:\Users\12994\.conda\envs\openaikey\python.exe D:\my_progarm\watermarking-appold\send.py 24-Dec-23 10:05:12 - INFO - client: Initializing... 24-Dec-23 10:05:12 - INFO - client: Loading WhatsApp WEB 24-Dec-23 10:05:13 - INFO - client: WhatsApp WEB loaded 24-Dec-23 10:05:13 - INFO - client: Page loaded 24-Dec-23 10:05:13 - INFO - client: Injecting wapi.js 24-Dec-23 10:05:13 - INFO - client: Start WPPConfig 24-Dec-23 10:05:13 - INFO - client: WPPConfig 24-Dec-23 10:05:13 - DEBUG - client: start inject 24-Dec-23 10:05:13 - INFO - client: http => Waiting page load 24-Dec-23 10:05:13 - INFO - client: injected state: False 24-Dec-23 10:05:43 - ERROR - Exception in callback AsyncIOEventEmitter._emit_run.<locals>._callback(<Task finishe...s exceeded.')>) at C:\Users\12994\.conda\envs\openaikey\lib\site-packages\pyee\_asyncio.py:55 handle: <Handle AsyncIOEventEmitter._emit_run.<locals>._callback(<Task finishe...s exceeded.')>) at C:\Users\12994\.conda\envs\openaikey\lib\site-packages\pyee\_asyncio.py:55> Traceback (most recent call last): File "C:\Users\12994\.conda\envs\openaikey\lib\asyncio\events.py", line 81, in _run self._context.run(self._callback, *self._args) File "C:\Users\12994\.conda\envs\openaikey\lib\site-packages\pyee\_asyncio.py", line 62, in _callback self.emit('error', exc) File "C:\Users\12994\.conda\envs\openaikey\lib\site-packages\pyee\_base.py", line 116, in emit self._emit_handle_potential_error(event, args[0] if args else None) File "C:\Users\12994\.conda\envs\openaikey\lib\site-packages\pyee\_base.py", line 86, in _emit_handle_potential_error raise error File "C:\Users\12994\.conda\envs\openaikey\lib\site-packages\WPP_Whatsapp\api\layers\HostLayer.py", line 63, in on_load await self._afterPageLoad() File "C:\Users\12994\.conda\envs\openaikey\lib\site-packages\WPP_Whatsapp\api\layers\HostLayer.py", line 80, in _afterPageLoad if await self.inject_api(): File "C:\Users\12994\.conda\envs\openaikey\lib\site-packages\WPP_Whatsapp\api\layers\HostLayer.py", line 451, in inject_api await self.ThreadsafeBrowser.page_wait_for_function( File "C:\Users\12994\.conda\envs\openaikey\lib\site-packages\WPP_Whatsapp\PlaywrightSafeThread\browser\threadsafe_browser.py", line 364, in page_wait_for_function return await self.page.wait_for_function(expression, arg=arg, timeout=timeout, polling=polling) File "C:\Users\12994\.conda\envs\openaikey\lib\site-packages\playwright\async_api\_generated.py", line 9364, in wait_for_function await self._async( File "C:\Users\12994\.conda\envs\openaikey\lib\site-packages\playwright\_impl\_page.py", line 851, in wait_for_function return await self._main_frame.wait_for_function(**locals_to_params(locals())) File "C:\Users\12994\.conda\envs\openaikey\lib\site-packages\playwright\_impl\_frame.py", line 662, in wait_for_function return from_channel(await self._channel.send("waitForFunction", params)) File "C:\Users\12994\.conda\envs\openaikey\lib\site-packages\playwright\_impl\_connection.py", line 39, in send return await self.inner_send(method, params, False) File "C:\Users\12994\.conda\envs\openaikey\lib\site-packages\playwright\_impl\_connection.py", line 63, in inner_send result = next(iter(done)).result() playwright._impl._api_types.TimeoutError: Timeout 30000ms exceeded.
You are right, but the terminal still has a warning when it is running correctly, but it does not affect the transmission. My code and Terminal output
from WPP_Whatsapp import Create
import logging
from datetime import datetime
current_time = datetime.now().strftime("log_%Y_%m_%d_%H_%M_%S.log")
logger = logging.getLogger(name="WPP_Whatsapp")
logger.setLevel(logging.DEBUG)
file_handler = logging.FileHandler(current_time)
file_handler.setLevel(logging.DEBUG) #
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
# start client with your session name
your_session_name = "client"
creator = Create(session=your_session_name, browser="firefox", headless=True)
client = creator.start()
# Now scan Whatsapp Qrcode in browser
# check state of login
if creator.state != 'CONNECTED':
raise Exception(creator.state)
message = "hello from wpp"
phone_number = "+xxxx232849776" # or "+201016708170"
# example
# Simple message
result = client.sendText(phone_number, message)
print(type(result))
print(result)
img_result = client.sendImage(to=phone_number, filePath=r"C:\my_program\Asahngdan\watermarking-app\images\logo.png",
filename='logo.png')
print(img_result)
# creator.sync_close()
"""
sendText:
Sends a text message to given chat
@category Chat
@param to chat id: xxxxx@us.c
@param content text message
@option dict
return dict -> {'id': 'true_**********@c.us_*************_out', 'ack': 3, 'sendMsgResult': {}}
"""
25-Dec-23 09:05:01 - INFO - client: Initializing...
25-Dec-23 09:05:01 - INFO - client: Loading WhatsApp WEB
Exception in thread Thread-2 (_loop_):
Traceback (most recent call last):
File "C:\ProgramData\anaconda3\Lib\threading.py", line 1038, in _bootstrap_inner
self.run()
File "C:\ProgramData\anaconda3\Lib\threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "C:\ProgramData\anaconda3\Lib\site-packages\WPP_Whatsapp\api\Whatsapp.py", line 54, in _loop_
func()
File "C:\ProgramData\anaconda3\Lib\site-packages\WPP_Whatsapp\api\Whatsapp.py", line 62, in __intervalHandel
newConnected = self.ThreadsafeBrowser.sync_page_evaluate("() => WPP && WPP.conn.isRegistered()")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\ProgramData\anaconda3\Lib\site-packages\WPP_Whatsapp\PlaywrightSafeThread\browser\threadsafe_browser.py", line 360, in sync_page_evaluate
raise error
File "C:\ProgramData\anaconda3\Lib\site-packages\WPP_Whatsapp\PlaywrightSafeThread\browser\threadsafe_browser.py", line 353, in sync_page_evaluate
return self.run_threadsafe(self.page.evaluate, expression, arg)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\ProgramData\anaconda3\Lib\site-packages\WPP_Whatsapp\PlaywrightSafeThread\browser\threadsafe_browser.py", line 407, in run_threadsafe
result = future.result(timeout=10)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\ProgramData\anaconda3\Lib\concurrent\futures\_base.py", line 456, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "C:\ProgramData\anaconda3\Lib\concurrent\futures\_base.py", line 401, in __get_result
raise self._exception
File "C:\Users\12994\AppData\Roaming\Python\Python311\site-packages\playwright\async_api\_generated.py", line 8330, in evaluate
await self._impl_obj.evaluate(
File "C:\Users\12994\AppData\Roaming\Python\Python311\site-packages\playwright\_impl\_page.py", line 407, in evaluate
return await self._main_frame.evaluate(expression, arg)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\12994\AppData\Roaming\Python\Python311\site-packages\playwright\_impl\_frame.py", line 277, in evaluate
await self._channel.send(
File "C:\Users\12994\AppData\Roaming\Python\Python311\site-packages\playwright\_impl\_connection.py", line 44, in send
return await self._connection.wrap_api_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\12994\AppData\Roaming\Python\Python311\site-packages\playwright\_impl\_connection.py", line 419, in wrap_api_call
return await cb()
^^^^^^^^^^
File "C:\Users\12994\AppData\Roaming\Python\Python311\site-packages\playwright\_impl\_connection.py", line 79, in inner_send
result = next(iter(done)).result()
^^^^^^^^^^^^^^^^^^^^^^^^^
playwright._impl._api_types.Error: WPP is not defined
@debugger eval code line 197 > eval:1:7
evaluate@debugger eval code:204:19
@debugger eval code:1:44
25-Dec-23 09:05:02 - INFO - client: WhatsApp WEB loaded
25-Dec-23 09:05:02 - INFO - client: Page loaded
25-Dec-23 09:05:02 - INFO - client: Injecting wapi.js
25-Dec-23 09:05:02 - INFO - client: Start WPPConfig
25-Dec-23 09:05:02 - INFO - client: WPPConfig
25-Dec-23 09:05:02 - DEBUG - client: start inject
25-Dec-23 09:05:02 - INFO - client: http => Waiting page load
25-Dec-23 09:05:02 - INFO - client: injected state: False
25-Dec-23 09:05:07 - INFO - client: wapi.js injected
25-Dec-23 09:05:07 - INFO - client: WhatsApp WEB version: 2.2353.59
25-Dec-23 09:05:07 - INFO - client: WA-JS version: 2.28.2-alpha.0
25-Dec-23 09:05:07 - DEBUG - client: Exposing onMessage function
25-Dec-23 09:05:07 - DEBUG - client: Exposing onAnyMessage function
25-Dec-23 09:05:07 - DEBUG - client: Exposing onAck function
25-Dec-23 09:05:07 - DEBUG - client: Exposing onNotificationMessage function
25-Dec-23 09:05:07 - DEBUG - client: Exposing onParticipantsChanged function
25-Dec-23 09:05:07 - DEBUG - client: Exposing onStateChange function
25-Dec-23 09:05:08 - INFO - client: http => Checking is logged...
25-Dec-23 09:05:08 - DEBUG - client: http => authenticated=True
25-Dec-23 09:05:08 - INFO - client: Auto close configured to 60s
25-Dec-23 09:05:08 - INFO - client: Authenticated
25-Dec-23 09:05:08 - DEBUG - client: clearInterval <threading.Event at 0x2191b962ad0: unset>
25-Dec-23 09:05:08 - DEBUG - client: Exposing onStreamChange function
25-Dec-23 09:05:08 - DEBUG - client: Exposing onIncomingCall function
25-Dec-23 09:05:08 - DEBUG - client: Exposing onInterfaceChange function
25-Dec-23 09:05:08 - DEBUG - client: Exposing onPresenceChanged function
25-Dec-23 09:05:08 - DEBUG - client: Exposing onLiveLocation function
25-Dec-23 09:05:08 - DEBUG - client: Exposing onAddedToGroup function
25-Dec-23 09:05:08 - DEBUG - client: Exposing onRevokedMessage function
25-Dec-23 09:05:08 - DEBUG - client: Exposing onReactionMessage function
25-Dec-23 09:05:08 - DEBUG - client: Exposing onPollResponse function
25-Dec-23 09:05:08 - INFO - client: http => Checking phone is connected...
25-Dec-23 09:05:16 - INFO - client: http => Connected
25-Dec-23 09:05:16 - DEBUG - client: clearInterval <threading.Event at 0x2191b962ad0: set>
25-Dec-23 09:05:16 - DEBUG - client: Registering onStateChange event
25-Dec-23 09:05:17 - DEBUG - client: Send Message send_result={'id': 'true_8618232849776@c.us_3EB02C40A1D6A7D64DA59D_out', 'ack': 3, 'sendMsgResult': {}}
<class 'dict'>
{'id': 'true_8618232849776@c.us_3EB02C40A1D6A7D64DA59D_out', 'ack': 3, 'sendMsgResult': {}}
{'ack': 3, 'id': 'true_xxxx232849776@c.us_3EB08BA6E6950F71396103_out', 'sendMsgResult': {'messageSendResult': 'OK'}, 'error': None}
ok, i fix it
update from git
pip install git+https://github.com/3mora2/WPP_Whatsapp
ok, i fix it update from git
pip install git+https://github.com/3mora2/WPP_Whatsapp
yes
"When I am using
Hidden Browser creator = Create(session=your_session_name, headless=True) it throws an error, and the subsequent logic cannot execute normally."
`Traceback (most recent call last): File "D:\my_progarm\pythonProject\main.py", line 6, in
client = creator.start()
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\WPP_Whatsapp\controllers\initializer.py", line 117, in start
self.create()
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\WPP_Whatsapp\controllers\initializer.py", line 154, in create
self.client.start()
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\WPP_Whatsapp\api\layers\HostLayer.py", line 103, in start
self.initWhatsapp()
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\WPP_Whatsapp\api\layers\HostLayer.py", line 113, in initWhatsapp
self.ThreadsafeBrowser.sync_goto(whatsappUrl, wait_until="domcontentloaded")
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\WPP_Whatsapp\PlaywrightSafeThread\browser\threadsafe_browser.py", line 401, in sync_goto
self.run_threadsafe(self.page.goto, *args, kwargs)
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\WPP_Whatsapp\PlaywrightSafeThread\browser\threadsafe_browser.py", line 407, in run_threadsafe
result = future.result(timeout=10)
File "C:\Users\12994.conda\envs\openaikey\lib\concurrent\futures_base.py", line 444, in result
return self.get_result()
File "C:\Users\12994.conda\envs\openaikey\lib\concurrent\futures_base.py", line 389, in get_result
raise self._exception
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\playwright\async_api_generated.py", line 7533, in goto
await self._async(
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\playwright_impl_page.py", line 487, in goto
return await self._main_frame.goto(locals_to_params(locals()))
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\playwright_impl_frame.py", line 122, in goto
await self._channel.send("goto", locals_to_params(locals()))
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\playwright_impl_connection.py", line 39, in send
return await self.inner_send(method, params, False)
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\playwright_impl_connection.py", line 63, in inner_send
result = next(iter(done)).result()
playwright._impl._api_types.Error: net::ERR_CONNECTION_RESET at https://web.whatsapp.com/
=========================== logs ===========================
navigating to "https://web.whatsapp.com/", waiting until "domcontentloaded"
21-Dec-23 18:29:21 - ERROR - Exception in callback AsyncIOEventEmitter._emit_run.._callback(<Task finishe...s exceeded.')>) at C:\Users\12994.conda\envs\openaikey\lib\site-packages\pyee_asyncio.py:55
handle: <Handle AsyncIOEventEmitter._emit_run.._callback(<Task finishe...s exceeded.')>) at C:\Users\12994.conda\envs\openaikey\lib\site-packages\pyee_asyncio.py:55>
Traceback (most recent call last):
File "C:\Users\12994.conda\envs\openaikey\lib\asyncio\events.py", line 81, in _run
self._context.run(self._callback, *self._args)
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\pyee_asyncio.py", line 62, in _callback
self.emit('error', exc)
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\pyee_base.py", line 116, in emit
self._emit_handle_potential_error(event, args[0] if args else None)
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\pyee_base.py", line 86, in _emit_handle_potential_error
raise error
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\WPP_Whatsapp\api\layers\HostLayer.py", line 63, in on_load
await self._afterPageLoad()
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\WPP_Whatsapp\api\layers\HostLayer.py", line 80, in _afterPageLoad
if await self.inject_api():
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\WPP_Whatsapp\api\layers\HostLayer.py", line 450, in inject_api
await self.ThreadsafeBrowser.page_wait_for_function(
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\WPP_Whatsapp\PlaywrightSafeThread\browser\threadsafe_browser.py", line 365, in page_wait_for_function
return await self.page.wait_for_function(expression, arg=arg, timeout=timeout, polling=polling)
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\playwright\async_api_generated.py", line 9364, in wait_for_function
await self._async(
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\playwright_impl_page.py", line 851, in wait_for_function
return await self._main_frame.wait_for_function(*locals_to_params(locals()))
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\playwright_impl_frame.py", line 662, in wait_for_function
return from_channel(await self._channel.send("waitForFunction", params))
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\playwright_impl_connection.py", line 39, in send
return await self.inner_send(method, params, False)
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\playwright_impl_connection.py", line 63, in inner_send
result = next(iter(done)).result()
playwright._impl._api_types.TimeoutError: Timeout 30000ms exceeded.
21-Dec-23 18:32:47 - ERROR - Exception in callback AsyncIOEventEmitter._emit_run.._callback(<Task finishe...seInterval'")>) at C:\Users\12994.conda\envs\openaikey\lib\site-packages\pyee_asyncio.py:55
handle: <Handle AsyncIOEventEmitter._emit_run.._callback(<Task finishe...seInterval'")>) at C:\Users\12994.conda\envs\openaikey\lib\site-packages\pyee_asyncio.py:55>
Traceback (most recent call last):
File "C:\Users\12994.conda\envs\openaikey\lib\asyncio\events.py", line 81, in _run
self._context.run(self._callback, self._args)
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\pyee_asyncio.py", line 62, in _callback
self.emit('error', exc)
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\pyee_base.py", line 116, in emit
self._emit_handle_potential_error(event, args[0] if args else None)
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\pyee_base.py", line 86, in _emit_handle_potential_error
raise error
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\WPP_Whatsapp\api\layers\HostLayer.py", line 59, in on_close
self.cancelAutoClose()
File "C:\Users\12994.conda\envs\openaikey\lib\site-packages\WPP_Whatsapp\api\layers\HostLayer.py", line 229, in cancelAutoClose
self.clearInterval(self.autoCloseInterval)
AttributeError: 'Whatsapp' object has no attribute 'autoCloseInterval'
cannot join current thread`