Skip to content

[Bug]: Download.failure() raises TypeError: expected string or bytes-like object, got 'NoneType' #2408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
heisenborg-actual opened this issue Apr 16, 2024 · 0 comments · Fixed by #2409

Comments

@heisenborg-actual
Copy link

Version

1.43.0

Steps to reproduce

from playwright.sync_api import sync_playwright

with sync_playwright() as playwright:
    browser = playwright.chromium.launch()
    page = browser.new_page()
    with page.expect_download() as download:
        try:
            page.goto('https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf')
        except:
            pass
        print(download.value.path())
        print(download.value.suggested_filename)
        print(download.value.failure())

Expected behavior

I expect the call to download.failure() to return None because the download was successful.

Actual behavior

/tmp/playwright-artifacts-4txmfy/033b3677-12a1-472e-9eeb-44041ffbd299
dummy.pdf
Traceback (most recent call last):
  File "/usr/local/app/dl-fail.py", line 13, in <module>
    print(download.value.failure())
          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/playwright/sync_api/_generated.py", line 6953, in failure
    return mapping.from_maybe_impl(self._sync(self._impl_obj.failure()))
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/playwright/_impl/_sync_base.py", line 115, in _sync
    return task.result()
           ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/playwright/_impl/_download.py", line 55, in failure
    return await self._artifact.failure()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/playwright/_impl/_artifact.py", line 45, in failure
    return patch_error_message(await self._channel.send("failure"))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/playwright/_impl/_helper.py", line 228, in patch_error_message
    match = re.match(r"(\w+)(: expected .*)", message)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/re/__init__.py", line 167, in match
    return _compile(pattern, flags).match(string)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'

Additional context

No response

Environment

- Operating System: Debian 12 / Bookworm
- CPU: x86_64
- Browser: Chromium
- Python Version: 3.12.3
- Other info: Running in a docker container on MacOS 14.4.1 via Docker Desktop using python:3.12-bookworm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant