elebumm / RedditVideoMakerBot

Create Reddit Videos with just✨ one command ✨

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Timeout 30000ms exceeded even after new UI layout when taking screenshots

mikkoxs opened this issue · comments

Describe the bug

When the bot tries to take screenshots of individual comments, it times out.

Reproduction Steps

After updating to code relevant for the new UI, it worked yesterday however, today it seems to be stuck on taking screenshots and chromium freezes

Expected behavior

  • The bot to take screenshots of all the comments
  • compile the video

Screenshots

image

  File "/Users/mikko/Developer/RedditVideoMakerBot/main.py", line 132, in <module>
    raise err
  File "/Users/mikko/Developer/RedditVideoMakerBot/main.py", line 111, in <module>
    main(post_id)
  File "/Users/mikko/Developer/RedditVideoMakerBot/main.py", line 53, in main
    get_screenshots_of_reddit_posts(reddit_object, number_of_comments)
  File "/Users/mikko/Developer/RedditVideoMakerBot/video_creation/screenshot_downloader.py", line 266, in get_screenshots_of_reddit_posts
    page.locator(f"#t1_{comment['comment_id']}-comment-rtjson-content").screenshot(
  File "/Users/mikko/Developer/RedditVideoMakerBot/venv/lib/python3.10/site-packages/playwright/sync_api/_generated.py", line 17568, in screenshot
    self._sync(
  File "/Users/mikko/Developer/RedditVideoMakerBot/venv/lib/python3.10/site-packages/playwright/_impl/_sync_base.py", line 109, in _sync
    return task.result()
  File "/Users/mikko/Developer/RedditVideoMakerBot/venv/lib/python3.10/site-packages/playwright/_impl/_locator.py", line 529, in screenshot
    return await self._with_element(
  File "/Users/mikko/Developer/RedditVideoMakerBot/venv/lib/python3.10/site-packages/playwright/_impl/_locator.py", line 115, in _with_element
    handle = await self.element_handle(timeout=timeout)
  File "/Users/mikko/Developer/RedditVideoMakerBot/venv/lib/python3.10/site-packages/playwright/_impl/_locator.py", line 315, in element_handle
    handle = await self._frame.wait_for_selector(
  File "/Users/mikko/Developer/RedditVideoMakerBot/venv/lib/python3.10/site-packages/playwright/_impl/_frame.py", line 322, in wait_for_selector
    await self._channel.send("waitForSelector", locals_to_params(locals()))
  File "/Users/mikko/Developer/RedditVideoMakerBot/venv/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 61, in send
    return await self._connection.wrap_api_call(
  File "/Users/mikko/Developer/RedditVideoMakerBot/venv/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 482, in wrap_api_call
    return await cb()
  File "/Users/mikko/Developer/RedditVideoMakerBot/venv/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 97, in inner_send
    result = next(iter(done)).result()
playwright._impl._api_types.TimeoutError: Timeout 30000ms exceeded.
=========================== logs ===========================
waiting for locator("#t1_ksf1z8o-comment-rtjson-content")
============================================================
╭──────────────────────────────────────────────────────────────────────────────╮
│ Sorry, something went wrong with this version! Try again, and feel free to   │
│ report this issue at GitHub or the Discord community.                        │
│ Version: 3.2.1                                                               │
│ Error: Timeout 30000ms exceeded.                                             │
│ =========================== logs ===========================                 │
│ waiting for locator("#t1_ksf1z8o-comment-rtjson-content")                    │
│ ============================================================                 │
│ Config: {'allow_nsfw': False, 'theme': 'light', 'times_to_run': 10,          │
│ 'opacity': 0.9, 'storymode': False, 'storymodemethod': 1,                    │
│ 'storymode_max_length': 1000, 'resolution_w': 1080, 'resolution_h': 1920,    │
│ 'zoom': 1.0, 'background': {'background_video': 'minecraft',                 │
│ 'background_audio': 'lofi', 'background_audio_volume': 0.03,                 │
│ 'enable_extra_audio': False, 'background_thumbnail': True,                   │
│ 'background_thumbnail_font_family': 'arial',                                 │
│ 'background_thumbnail_font_size': 96, 'background_thumbnail_font_color':     │
│ '255,255,255'}, 'tts': {'voice_choice': 'tiktok', 'random_voice': False,     │
│ 'elevenlabs_voice_name': 'Bella', 'elevenlabs_api_key': 'REDACTED',          │
│ 'aws_polly_voice': 'Matthew', 'streamlabs_polly_voice': 'Matthew',           │
│ 'tiktok_voice': 'en_us_001', 'tiktok_sessionid': 'REDACTED', 'python_voice': │
│ '1', 'py_voice_num': '2', 'silence_duration': 0.3, 'no_emojis': False}}      │
╰──────────────────────────────────────────────────────────────────────────────╯

System Information

Operating System : MacOS
Python version : Python 3.10
App version / Branch : Pycharm

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.

Additional Context

No response

#1960 Please check this.

I changed the playwright script to be headless:fasle and fixed this issue while trying to get this running today.

video_creation\screenshot_downloader.py

commented

it

I changed the playwright script to be headless:fasle and fixed this issue while trying to get this running today.

video_creation\screenshot_downloader.py

it worked at first but got this error after :

Launching Headless Browser...
Logging in to Reddit...
Skipping translation...
Something went wrong!
Something went wrong with making the screenshots! Do you want to skip the post? (y/n) n
Do you want the error traceback for debugging purposes? (y/n)y
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Sorry, something went wrong with this version! Try again, and feel free to report this issue at GitHub or the Discord community.  │
│ Version: 3.2.1                                                                                                                    │
│ Error: Timeout 30000ms exceeded.                                                                                                  │
│ =========================== logs ===========================                                                                      │
│ waiting for locator("[data-test-id=\"post-content\"]")                                                                            │
│ ============================================================                                                                      │
│ Config: {'allow_nsfw': False, 'theme': 'light', 'times_to_run': 1, 'opacity': 0.9, 'storymode': False, 'storymodemethod': 1,      │
│ 'storymode_max_length': 1000, 'resolution_w': 1080, 'resolution_h': 1920, 'zoom': 1.0, 'background': {'background_video':         │
│ 'minecraft', 'background_audio': 'lofi', 'background_audio_volume': 0.15, 'enable_extra_audio': False, 'background_thumbnail':    │
│ False, 'background_thumbnail_font_family': 'arial', 'background_thumbnail_font_size': 96, 'background_thumbnail_font_color':      │
│ '255,255,255'}, 'tts': {'voice_choice': 'tiktok', 'random_voice': True, 'elevenlabs_voice_name': 'Bella', 'elevenlabs_api_key':   │
│ 'REDACTED', 'aws_polly_voice': 'Matthew', 'streamlabs_polly_voice': 'Matthew', 'tiktok_voice': 'en_us_001', 'tiktok_sessionid':   │
│ 'REDACTED', 'python_voice': '1', 'py_voice_num': '2', 'silence_duration': 0.3, 'no_emojis': False}}                               │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Traceback (most recent call last):
  File "C:\Users\DIR\Desktop\RedditVideoMakerBot\main.py", line 131, in <module>
    raise err
  File "C:\Users\DIR\Desktop\RedditVideoMakerBot\main.py", line 113, in <module>
    run_many(config["settings"]["times_to_run"])
  File "C:\Users\DIR\Desktop\RedditVideoMakerBot\main.py", line 68, in run_many
    main()
  File "C:\Users\DIR\Desktop\RedditVideoMakerBot\main.py", line 52, in main
    get_screenshots_of_reddit_posts(reddit_object, number_of_comments)
  File "C:\Users\DIR\Desktop\RedditVideoMakerBot\video_creation\screenshot_downloader.py", line 203, in get_screenshots_of_reddit_posts
    raise e
  File "C:\Users\DIR\Desktop\RedditVideoMakerBot\video_creation\screenshot_downloader.py", line 185, in get_screenshots_of_reddit_posts
    page.locator('[data-test-id="post-content"]').screenshot(path=postcontentpath)
  File "C:\Users\DIR\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\sync_api\_generated.py", line 17568, in screenshot
    self._sync(
  File "C:\Users\DIR\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_sync_base.py", line 109, in _sync
    return task.result()
  File "C:\Users\DIR\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_locator.py", line 529, in screenshot
    return await self._with_element(
  File "C:\Users\DIR\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_locator.py", line 115, in _with_element
    handle = await self.element_handle(timeout=timeout)
  File "C:\Users\DIR\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_locator.py", line 315, in element_handle
    handle = await self._frame.wait_for_selector(
  File "C:\Users\DIR\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_frame.py", line 322, in wait_for_selector
    await self._channel.send("waitForSelector", locals_to_params(locals()))
  File "C:\Users\DIR\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_connection.py", line 61, in send
    return await self._connection.wrap_api_call(
  File "C:\Users\DIR\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_connection.py", line 482, in wrap_api_call
    return await cb()
  File "C:\Users\DIR\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_connection.py", line 97, in inner_send
    result = next(iter(done)).result()
playwright._impl._api_types.TimeoutError: Timeout 30000ms exceeded.
=========================== logs ===========================
waiting for locator("[data-test-id=\"post-content\"]")
============================================================

I´m having a similar issue when loggin in to Reddit.

image

Traceback (most recent call last): File "D:\Usuarios\Miguel\Documentos\PROGRAMACION\Repos\pythonVideoMaker\main.py", line 132, in <module> raise err File "D:\Usuarios\Miguel\Documentos\PROGRAMACION\Repos\pythonVideoMaker\main.py", line 114, in <module> run_many(config["settings"]["times_to_run"]) File "D:\Usuarios\Miguel\Documentos\PROGRAMACION\Repos\pythonVideoMaker\main.py", line 69, in run_many main() await self._channel.send("fill", locals_to_params(locals())) File "C:\Users\Miguel\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_connection.py", line 61, in send return await self._connection.wrap_api_call( File "C:\Users\Miguel\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_connection.py", line 482, in wrap_api_call return await cb() File "C:\Users\Miguel\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_connection.py", line 97, in inner_send result = next(iter(done)).result() playwright._impl._api_types.TimeoutError: Timeout 30000ms exceeded. =========================== logs =========================== waiting for locator("[name=\"username\"]") ============================================================

I think maybe it´s not finding the username in the config.toml, but it´s actually over there

I would appreciate any help

Same problem here - Timeout at first (30000ms on waiting for locator username). Changed the browser to headless: False -> Turned intot "Error: strict mode violation, username resolved to 3 elements." Unfortunately wont work.

I have a similar problem:

Logging in to Reddit... ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ Sorry, something went wrong with this version! Try again, and feel free to report this issue at GitHub or the Discord community. │ │ Version: 3.2.1 │ │ Error: Timeout 30000ms exceeded. │ │ =========================== logs =========================== │ │ waiting for locator("[name=\"username\"]") │ │ ============================================================ │ │ Config: {'allow_nsfw': False, 'theme': 'dark', 'times_to_run': 1, 'opacity': 0.9, 'storymode': False, 'storymodemethod': 1, 'storymode_max_length': 1000, 'resolution_w': 1080, │ │ 'resolution_h': 1920, 'zoom': 1.0, 'background': {'background_video': 'minecraft', 'background_audio': 'lofi', 'background_audio_volume': 0.15, 'enable_extra_audio': False, │ │ 'background_thumbnail': False, 'background_thumbnail_font_family': 'arial', 'background_thumbnail_font_size': 96, 'background_thumbnail_font_color': '255,255,255'}, 'tts': │ │ {'random_voice': True, 'elevenlabs_voice_name': 'Bella', 'elevenlabs_api_key': 'REDACTED', 'aws_polly_voice': 'Matthew', 'streamlabs_polly_voice': 'Matthew', 'tiktok_voice': │ │ 'en_us_001', 'tiktok_sessionid': 'REDACTED', 'python_voice': '1', 'py_voice_num': '2', 'silence_duration': 0.3, 'no_emojis': False, 'voice_choice': 'pyttsx'}} │ └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ Traceback (most recent call last): File "C:\OFFLINEPROJECTS\BOTS\RedditVideo\main.py", line 132, in <module> raise err File "C:\OFFLINEPROJECTS\BOTS\RedditVideo\main.py", line 114, in <module> run_many(config["settings"]["times_to_run"]) File "C:\OFFLINEPROJECTS\BOTS\RedditVideo\main.py", line 69, in run_many main() File "C:\OFFLINEPROJECTS\BOTS\RedditVideo\main.py", line 53, in main get_screenshots_of_reddit_posts(reddit_object, number_of_comments) File "C:\OFFLINEPROJECTS\BOTS\RedditVideo\video_creation\screenshot_downloader.py", line 103, in get_screenshots_of_reddit_posts page.locator('[name="username"]').fill(settings.config["reddit"]["creds"]["username"]) File "C:\Users\carlo\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\sync_api\_generated.py", line 16045, in fill self._sync( File "C:\Users\carlo\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_sync_base.py", line 109, in _sync return task.result() File "C:\Users\carlo\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_locator.py", line 212, in fill return await self._frame.fill(self._selector, strict=True, **params) File "C:\Users\carlo\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_frame.py", line 528, in fill await self._channel.send("fill", locals_to_params(locals())) File "C:\Users\carlo\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_connection.py", line 61, in send return await self._connection.wrap_api_call( File "C:\Users\carlo\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_connection.py", line 482, in wrap_api_call return await cb() File "C:\Users\carlo\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_connection.py", line 97, in inner_send result = next(iter(done)).result() playwright._impl._api_types.TimeoutError: Timeout 30000ms exceeded. =========================== logs =========================== waiting for locator("[name=\"username\"]") ============================================================

image

Any solution?

username resolved to 3 elements

I also got this issue and the problem is noted there-- when looking for the username, it found 3 elements. When you resolve username, you notice the same issue happens for password as well as similarly for the login button. To solve this issue, it's better to precisely target the username input where the login info will go to.

Replace the steps code at around line 82 in screenshot_downloader.py to:

...
    with sync_playwright() as p:
        print_substep("Launching Headless Browser...")
        browser = p.chromium.launch(
            headless=False
        )  # headless=False will show the browser for debugging purposes
        # Device scale factor (or dsf for short) allows us to increase the resolution of the screenshots
        # When the dsf is 1, the width of the screenshot is 600 pixels
        # so we need a dsf such that the width of the screenshot is greater than the final resolution of the video
        dsf = (W // 600) + 1

        context = browser.new_context(
            locale=lang or "en-us",
            color_scheme="dark",
            viewport=ViewportSize(width=W, height=H),
            device_scale_factor=dsf,
        )
        cookies = json.load(cookie_file)
        cookie_file.close()

        context.add_cookies(cookies)  # load preference cookies

        # Login to Reddit
        print_substep("Logging in to Reddit...")
        page = context.new_page()
        page.goto("https://www.reddit.com/login", timeout=0)
        page.set_viewport_size(ViewportSize(width=1920, height=1080))
        page.wait_for_load_state()
        page.wait_for_timeout(5000)  # Adjusted timeout for waiting

        # Wait for the username field to be ready and fill it in
        page.wait_for_selector("input#login-username")
        page.locator("input#login-username").fill(
            settings.config["reddit"]["creds"]["username"]
        )

        # Wait for the password field to be ready and fill it in
        page.wait_for_selector("input#login-password")
        page.locator("input#login-password").fill(
            settings.config["reddit"]["creds"]["password"]
        )

        # Click the login button using the updated selector based on the provided HTML structure
        login_button_selector = "button.login:has-text('Log In')"
        page.wait_for_selector(login_button_selector)
        page.click(login_button_selector)

        page.wait_for_timeout(5000)
...

Hey everyone , same problem here as well but i am running the bot in the command line:
here is the full log:

╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Downloading screenshots of reddit posts... │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
Launching Headless Browser...
Logging in to Reddit...
╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Sorry, something went wrong with this version! Try again, and feel free to report this issue at │
│ GitHub or the Discord community. │
│ Version: 3.2.1 │
│ Error: Timeout 30000ms exceeded. │
│ =========================== logs =========================== │
│ waiting for locator("[name="username"]") │
│ ============================================================ │
│ Config: {'allow_nsfw': False, 'theme': 'dark', 'times_to_run': 3, 'opacity': 0.9, 'storymode': │
│ False, 'storymodemethod': 1, 'storymode_max_length': 1000, 'resolution_w': 1080, 'resolution_h': │
│ 1920, 'zoom': 1.0, 'background': {'background_video': 'minecraft', 'background_audio': 'lofi', │
│ 'background_audio_volume': 0.15, 'enable_extra_audio': False, 'background_thumbnail': False, │
│ 'background_thumbnail_font_family': 'arial', 'background_thumbnail_font_size': 96, │
│ 'background_thumbnail_font_color': '255,255,255'}, 'tts': {'voice_choice': 'elevenlabs', │
│ 'random_voice': False, 'elevenlabs_voice_name': 'Josh', 'elevenlabs_api_key': 'REDACTED', │
│ 'aws_polly_voice': 'Matthew', 'streamlabs_polly_voice': 'Matthew', 'tiktok_voice': 'y', │
│ 'tiktok_sessionid': 'REDACTED', 'python_voice': '1', 'py_voice_num': '2', 'silence_duration': │
│ 0.3, 'no_emojis': False}} │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
Traceback (most recent call last):
File "/content/reddit_bot/main.py", line 132, in
raise err
File "/content/reddit_bot/main.py", line 114, in
run_many(config["settings"]["times_to_run"])
File "/content/reddit_bot/main.py", line 69, in run_many
main()
File "/content/reddit_bot/main.py", line 53, in main
get_screenshots_of_reddit_posts(reddit_object, number_of_comments)
File "/content/reddit_bot/video_creation/screenshot_downloader.py", line 103, in get_screenshots_of_reddit_posts
page.locator('[name="username"]').fill(settings.config["reddit"]["creds"]["username"])
File "/usr/local/lib/python3.10/dist-packages/playwright/sync_api/_generated.py", line 16045, in fill
self._sync(
File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_sync_base.py", line 109, in _sync
return task.result()
File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_locator.py", line 212, in fill
return await self._frame.fill(self._selector, strict=True, **params)
File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_frame.py", line 528, in fill
await self._channel.send("fill", locals_to_params(locals()))
File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_connection.py", line 61, in send
return await self._connection.wrap_api_call(
File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_connection.py", line 482, in wrap_api_call
return await cb()
File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_connection.py", line 97, in inner_send
result = next(iter(done)).result()
playwright._impl._api_types.TimeoutError: Timeout 30000ms exceeded.
=========================== logs ===========================
waiting for locator("[name="username"]")

the main issue is reddit shows 2 different login pages on different occasions with different values-- one where it's light and the form is on the left and one where it's dark / form is in the middle.

my solution works for the dark middle form; the original solution works for the light left form. too lazy to work on a solution where it checks which form it is to actually solve this someone can probably fix it

@temrb Thanks for the feedback!
how can I help to implement your solution for my project?
Are you against my contribution to help you with the implementation for solving the issue for the both version.? :)

i think quick way is for each input, username & password, is to check if the id #login-username / #login-password exists and if it does, run my posted logic. else, run the original logic.

this solves the main issue almost everyone has been reporting-- "After updating to code relevant for the new UI, it worked yesterday however, today it seems to be stuck"

or "sometimes it works sometimes it doesnt" this is due to reddit rendering 1 version over the other at times vice versa

@temrb thanks for your feedback , I will try to implement your solution.

Facing the issue: waiting for: locator("[data-test-id="post-content"]")

whereas I have managed to fix the login by editing the values:
page.locator('input[name="username"]').fill(settings.config["reddit"]["creds"]["username"])
page.locator('input[name="password"]').fill(settings.config["reddit"]["creds"]["password"])
page.locator('.login.button-brand').click()

@TT5H That sounds like a nice solution, thanks for sharing it 🙌👌

Facing the issue: waiting for: locator("[data-test-id="post-content"]")

Same issue after aplying @temrb solution

Facing the issue: waiting for: locator("[data-test-id="post-content"]")

Just hoping that they fix it ASAP.