Closed parthibd closed 5 years ago
async def wait_until_connect(driver):
async for evt in driver.stream.monitor_field('stream'):
if evt['value'] == Stream.Stream.CONNECTED:
return
Thanks!
I am trying to do this
await driver.stop()
await driver.start()
Its throwing me selenium.common.exceptions.InvalidSessionIdException: Message: Tried to run command without establishing a connection
. Why is that ?
Are you trying to stop before start?
No I am not . I started the driver using await driver.start()
.
When it fails? When you stop it or when you try to start again?
When I try to stop it . Here is the initialization code
@middleware
async def run_before_every_request(request, handler):
client_id = request.headers["client-id"]
api_key = request.headers["api-key"]
if api_key != API_KEY:
return web.json_response({"message": "Please provide correct API key", "status": False}, status=401)
if client_id not in drivers.keys():
async_loop = asyncio.get_event_loop()
profile_path = os.path.join(FIREFOX_PROFILES_PATH, client_id)
if not os.path.exists(profile_path):
os.makedirs(profile_path)
driver = whalesong.Whalesong(
profile=profile_path,
loadstyles=True,
loop=async_loop
)
await driver.start()
request["driver"] = driver
drivers[client_id] = driver
else:
request["driver"] = drivers[client_id]
return await handler(request)
That error is because connection with Selenium is lost. You initialitation looks ok. I can not see more.
What can I do to resolve it ? Bug within whalesong ?
I don't know. It could be a problem with your code. Can you test an script which starts and stops whalesong? If it fails it is a bug in Whalesong, otherwise it is your code.
Here is my test code
import asyncio
import os
import whalesong
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
PROFILE_PATH = os.path.join(BASE_DIR, 'test-profile')
async_loop = asyncio.get_event_loop()
driver: whalesong.Whalesong = whalesong.Whalesong(
profile=PROFILE_PATH,
loadstyles=True,
loop=async_loop
)
async def start():
await driver.start()
await driver.stop()
if __name__ == '__main__':
driver.loop.run_until_complete(start())
Same exception.
Ok, create a bug
Is there a way to wait for the driver status to be CONNECTED possibly with a timeout ?