daily-coding-problem / chatgpt-scraper

A Selenium-based ChatGPT interaction automation tool. This script initializes a browser session, interacts with ChatGPT using predefined prompts, and facilitates automated conversations with ChatGPT. Ideal for fetching responses and conducting tests or demonstrations.
2 stars 0 forks source link

TypeError: Binary Location Must be a String when Running docker compose run #1

Closed nicholasadamou closed 1 month ago

nicholasadamou commented 1 month ago

Description

When attempting to run the chatgpt-scraper project using Docker Compose, the following error occurs:

$ docker compose run --remove-orphans chatgpt-scraper --user-prompts "What is the meaning of life?"

[+] Creating 1/0
 ✔ Network chatgpt-scraper_default  Created                                                                                                                                                                                                  0.1s 
Skipping virtualenv creation, as specified in config file.

┌─┐┌─┐┌─┐    ┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐
│─┤├─┤ │     └─┐│  ├─┤├─┤├─┤├─ ├─┤
└─┘│   │     └─┘└─┘│└│┴ ┴│  └─┘│└│
gpt-scraper v1.0.0
A Selenium-based ChatGPT interaction automation tool. This script initializes a browser session, interacts with ChatGPT using predefined prompts, and facilitates automated conversations with ChatGPT. Ideal for fetching responses and conducting tests or demonstrations.
Author(s): Nicholas Adamou <nicholasadamouemail@gmail.com>
=====================================================================================================
2024-08-14 18:54:02,400 - INFO - patching driver executable /home/user/.local/share/undetected_chromedriver/undetected_chromedriver
Traceback (most recent call last):
  File "/usr/src/app/main.py", line 148, in <module>
    main(args.account, args.system_prompt, args.user_prompts, config)
  File "/usr/src/app/main.py", line 31, in main
    browser = Browser("https://chatgpt.com", config.headless)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/app/lib/chatgpt-scraper-lib/chatgpt/browser.py", line 18, in __init__
    self.driver = self._init_driver(headless)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/app/lib/chatgpt-scraper-lib/chatgpt/browser.py", line 51, in _init_driver
    driver = uc.Chrome(options=options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/undetected_chromedriver/__init__.py", line 372, in __init__
    options.binary_location = (
    ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/selenium/webdriver/chromium/options.py", line 52, in binary_location
    raise TypeError(self.BINARY_LOCATION_ERROR)
TypeError: Binary Location Must be a String

Steps to Reproduce

  1. Run the following command in the terminal:

    docker compose run --remove-orphans chatgpt-scraper --user-prompts "What is the meaning of life?"
  2. The container initializes, but the script fails with the TypeError: Binary Location Must be a String.

Expected Behavior

The script should initialize a browser session and interact with ChatGPT using predefined prompts without throwing an error.

Actual Behavior

The script throws a TypeError indicating that the binary_location in the Selenium WebDriver options must be a string, which leads to the failure of the script.

Possible Causes

Environment

Additional Information

Related

The issue found at undetected-chromedriver/issues/1927 suggest that this is a known issue currently with undetected-chromedriver v3.5.5.

nicholasadamou commented 1 month ago

Solution

Here’s an example of the required changes:

docker-compose.yml

services:
  chatgpt-scraper:
    build: .
    platform: linux/amd64
    volumes:
      - ./scripts/entrypoint.sh:/usr/src/app/entrypoint.sh
    env_file:
      - .env
    entrypoint: ["/usr/src/app/entrypoint.sh"]

Dockerfile

RUN apt-get update && \
    apt-get install -y \
        build-essential \
        curl \
        wget \
        gnupg && \
    # Download and install Google Chrome
    wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
    apt-get install -y ./google-chrome-stable_current_amd64.deb && \
    rm google-chrome-stable_current_amd64.deb && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

These changes should allow the script to run correctly under Rosetta 2 emulation on Apple Silicon.