Forums

Can't use selenium concurrently

I don't why my previous question was moderated and then deleted but, once again my question stands. I have hosted a website on PythonAnywhere that uses selenium. When more than one user tries to run the bot Harakiri error comes in the server log.


SERVER LOG

*** HARAKIRI ON WORKER 2 (pid: 485, try: 1) ***
HARAKIRI !!! worker 2 status !!!
HARAKIRI [core 0] 10.0.0.66 - POST /run-bot/ since 1645001048
HARAKIRI !!! end of worker 2 status !!!
DAMN ! worker 2 (pid: 485) died, killed by signal 9 :( trying respawn ...
Respawned uWSGI worker 2 (new pid: 590)
spawned 2 offload threads for uWSGI worker 2

ERROR LOG


Internal Server Error: /run-bot/
Traceback (most recent call last):
  File "/home/eyal360/.virtualenvs/fbvenv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/eyal360/.virtualenvs/fbvenv/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/eyal360/.virtualenvs/fbvenv/lib/python3.9/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/home/eyal360/fb_automation/posts/views.py", line 645, in runBot
    bot.runningBot(waiting_hours, curr_user)
  File "/home/eyal360/fb_automation/posts/fb_bot.py", line 106, in runningBot
    self.performActions(no_loops, curr_user, browser)
  File "/home/eyal360/fb_automation/posts/fb_bot.py", line 241, in performActions
    group_detail_id = post_object[0]['group_detail_id']
  File "/home/eyal360/.virtualenvs/fbvenv/lib/python3.9/site-packages/django/db/models/query.py", line 322, in __getitem__
    return qs._result_cache[0]
IndexError: list index out of range

I cant understand what the problem is. Do I need to add celery (But I think it isn't supported on PythonAnywhere ). What should I do? And What does this terms mean (HARAKIRI, uWSGI)

How does your code that is crashing look like?

What do you mean by the code? What do you want? You can look at my code if you want :)

HARAKIRI means that the worker (process) crashed. It crashes when it tries to execute this code:

File "/home/eyal360/fb_automation/posts/fb_bot.py", line 241, in
performActions
    group_detail_id = post_object[0]['group_detail_id']

You may debug it and check why post_object is an empty list there.

We generally discourage using selenium in a web app code -- instead you may want to delegate the selenium part to an Always on task as suggested in this help page.

The above error only comes, when another user uses the bot when already a process is running. Otherwise there is no error in line 241. This means this error comes along with HARAKIRI. What should I do?

HARAKIRI happens when a web request takes longer than 5 minutes to process. Make sure that every request gets response within 5 minutes: https://help.pythonanywhere.com/pages/MySiteIsSlow/

Hi Pythonanywhere Team I am running Headless Selenium App in Bash Console and I am trying to access WhatsApp web there. I am grabbing the image after loading the site "https://web.whatsapp.com/". But I only get a white blank which means the site is not accessible I guess. All other sites are working fine like youtube, google, etc but WhatsApp Web not working. Do I need to upgrade my account or this is some other problem? Please let me know.

Free accounts have restricted internet access to whitelisted domains (usually API endpoints) -- if you want to scrape, you need to upgrade.

Can you whitelist WhatsApp web please

Send us link to the API documentation and we'll consider it for the whitelist.

It's not an API, it's a web called WhatsApp-Web. Link here, "https://web.whatsapp.com/".

We can only whitelist APIs

If I upgrade my account, will it work then?

If you upgrade, then you will have unrestricted internet access and will not need to go through the whitelist.

I upgraded the account and checked if that gonna work or not. The website was working but it only stays online for some hours like 2 to 3 less time of CPU usage. It is so much expensive to pay a lot for just 1 website which you can add to your whitelist. Anyhow, I downgraded my account and according to your refund policy, I want my money back. Can I get it?

@BodyTime we've refunded your last payment, it should be processed within 5-10 working days.