[Python] TypeError: Failed to fetch when uploading CSV file using Playwright and Python

Discussão em 'Python' iniciado por Stack, Fevereiro 14, 2025.

  1. Stack

    Stack Membro Participativo

    Environment:

    Python with Playwright Running on localhost:8000 Chrome browser in non-headless mode

    Problem: I'm trying to upload a CSV file using Playwright with Python, but I'm getting the following errors in the console:

    Failed to load resource: the server responded with a status of 404 (Not Found) for favicon.ico POST http://localhost:8000/upload - net::ERR_H2_OR_QUIC_REQUIRED Uncaught (in promise) TypeError: Failed to fetch at handleSubmit
    enter image description here Pic with the isshu

    Code: Here's my Playwright test code:

    Here is the full code:

    https://github.com/BoazYashar/Shopic


    def test_response_format_and_values():
    with sync_playwright() as playwright:
    browser = playwright.chromium.launch(headless=False)
    page = browser.new_page()
    upload_page = UploadPage(page)

    # Upload a valid file and click on upload
    response = upload_page.upload_file("valid_products.csv")


    And here's the relevant page object code:

    class UploadPage(BasePage):
    def upload_file(self, file_name: str) -> str:
    self.navigate("http://localhost:8000")
    file_path = str(CSV_FILE_PATH / file_name)
    self.page.set_input_files(self.file_input_selector, file_path)
    self.page.wait_for_selector(self.upload_button_selector)
    self.page.click(self.upload_button_selector)
    self.page.wait_for_selector(self.message_selector)
    results = self.page.text_content(self.message_selector)
    return results



    What I've Tried: The file upload interface appears to be working (I can select the file), but the actual POST request to /upload is failing with a network error. Question: Why am I getting the ERR_H2_OR_QUIC_REQUIRED error and how can I fix it? The error suggests there might be an issue with the HTTP/2 protocol, but I'm not sure how to properly configure this for local development.

    What I've Tried:

    • I tried uploading the file in several different ways, but none worked
    • I attempted various HTTP/2 solutions suggested by ChatGPT

    Expected Behavior: The CSV file should be uploaded successfully to the local server and return a JSON response.

    Actual Behavior: The request fails with ERR_H2_OR_QUIC_REQUIRED and a TypeError: Failed to fetch error.

    Continue reading...

Compartilhe esta Página