You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

树莓派3用Python3+Selenium调用Firefox遇connection refused错误求助

Fixing "connection refused" Error with Selenium Firefox on Raspberry Pi 3

Hey there! That connection refused error is super common when setting up Selenium with Firefox on a Raspberry Pi—let's walk through the fixes step by step.

The Root Cause (Most Likely)

Selenium can't talk to Firefox directly—it needs a bridge called GeckoDriver to handle the communication. Chances are you haven't installed this driver, or it's not configured correctly for your Pi's ARM architecture.

Step 1: Make Sure Firefox is Installed

First, confirm you have Firefox (the ESR version is recommended for Raspberry Pi) installed:

firefox --version

If it's missing, install it with:

sudo apt update && sudo apt install firefox-esr -y

Step 2: Install GeckoDriver

This is the critical piece. You have two easy ways to get it:

Option 1: Install via APT (Simplest)

Raspberry Pi's repo has a pre-built GeckoDriver package. Run:

sudo apt install firefox-geckodriver -y

After installation, test if it works by running:

geckodriver

You should see output like 169... INFO Listening on 127.0.0.1:4444—that means it's ready.

Option 2: Manual Download (If APT Version is Outdated)

If the APT version doesn't match your Firefox version, grab the ARM-compatible GeckoDriver (look for builds matched to your Firefox release). Then:

  1. Extract the downloaded binary file
  2. Move it to a directory in your system PATH, like /usr/local/bin:
    sudo mv geckodriver /usr/local/bin/
    
  3. Make it executable:
    sudo chmod +x /usr/local/bin/geckodriver
    

Step 3: Update Your Test Script

Now, adjust your script to either:

  • Use the PATH-configured GeckoDriver (if you installed via APT or moved it to PATH):
    from selenium import webdriver
    from selenium.webdriver.firefox.options import Options
    
    # Add headless mode if you're running without a desktop
    options = Options()
    options.headless = True  # Remove this if you have a physical desktop connected
    
    driver = webdriver.Firefox(options=options)
    # Rest of your script stays the same...
    
  • Or specify the GeckoDriver path explicitly:
    driver = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver', options=options)
    

Extra Troubleshooting Tips

  • If you're running the Pi headless (no monitor), always use the headless option—Firefox can't launch a GUI without a display.
  • Check that your user has permission to run GeckoDriver (the chmod +x step takes care of this).
  • If you still get errors, try updating all packages: sudo apt update && sudo apt upgrade -y to ensure Firefox and GeckoDriver are on compatible versions.

内容的提问来源于stack exchange,提问作者Nick Evans

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:30:11