Skip to content

Troubleshooting the "Could not fetch config from http://127.0.0.1:7860" Error in Gradio Client

Are you encountering a frustrating red error message when using the pyVideoTrans software or calling Gradio applications in your code?

gradio_client.exceptions.ConnectionError: Could not fetch config from http://127.0.0.1:7860.

Don't worry, you're not alone. This is a very common issue when using gradio_client. This guide will help you troubleshoot from basic checks to uncovering the "culprit" and completely resolving this error.

Understanding the Error: What does it mean?

The error message literally means: "Unable to retrieve the configuration information from http://127.0.0.1:7860".

In simpler terms, your client program is like a messenger who needs to first go to the server's address (Server) to get a "menu" (i.e., the application's configuration information, such as the APIs available, inputs, and outputs) before it can start ordering (submitting data). This error means that your messenger couldn't even enter the server's door, let alone get the menu.

The root cause, 99% of the time, is not in gradio_client itself, but in blocked network communication between the client and the server.

Part 1: Basic Troubleshooting Checklist (Solves 80% of Issues)

Before diving deeper, let's complete a set of standard checks, which will resolve most situations.

Step 1: Is Your Gradio Server Actually Running?

This is the most common and easily overlooked reason.

  • How to check:

    1. Check the terminal: See if the terminal window where you started the Gradio application (e.g., by running python app.py) is still running. Is it showing any errors or has it exited? A normally running server will display:
      Running on local URL:  http://127.0.0.1:7860

    1. Test with a browser: This is the most critical test! Directly open the server address displayed in your browser, http://127.0.0.1:7860.
      • If you see the Gradio interface: Congratulations, the server is healthy! The problem lies elsewhere, please continue below.
      • If the browser displays "Unable to access" or "Connection refused": It means the server has not started successfully. Please fix your server code first so that it can run normally.

Step 2: Do the Address and Port Match Exactly?

Make sure your messenger didn't run to the wrong address.

  • How to check:

    • Server-side: Check the parameters of your app.launch(). If you wrote app.launch(server_port=8000), then the address is http://127.0.0.1:8000.
    • Client-side: Make sure the URL in Client() is exactly the same as the URL displayed when the server starts.
    python
    # Server is on port 7860
    # app.launch()
    
    # Client must connect to 7860
    from gradio_client import Client
    client = Client("http://127.0.0.1:7860/") # Correct
    # client = Client("http://localhost:7860/") # Also correct
    # client = Client("http://127.0.0.1:5010/") # Incorrect!

Step 3 (Special Cases): Are You Using Docker or a Virtual Machine?

Running a Gradio server in a Docker container is a common pitfall.

  • Explanation: Docker containers have their own network, and 127.0.0.1 inside the container refers to the container itself, not your computer.
  • Solution:
    1. Server-side: You must listen on 0.0.0.0 to accept connections from outside the container.
      python
      app.launch(server_name="0.0.0.0", server_port=7860)
    2. When starting the container: You must use the -p parameter to map the container port to your computer's port.
      bash
      # Map your computer's 7860 port to the container's 7860 port
      docker run -p 7860:7860 your_gradio_image
    3. Client-side: Connect to your computer's address http://127.0.0.1:7860.

The same principle applies to virtual machines.


Part 2: Uncovering the "Culprit" - That Unexpected Network Proxy (VPN Software)

If you've completed all the above checks and the problem persists, you may have encountered the same "culprit" as I did.

The ultimate discovery: The problem lies in running VPN or network proxy software (such as Clash, V2Ray, etc.)!

Why do proxy software interfere with local connections?

When you turn on the "System Proxy" or "Global Mode" of the proxy software, it takes over all network requests on your computer, including those sent to 127.0.0.1 (localhost).

The journey of this request should be: [Your client script] -> [Your operating system] -> [Your Gradio server script] (instantaneously)

But after enabling the system proxy, it becomes: [Your client script] -> [Your operating system] -> [**Proxy software**] -> ???

The proxy software may be "confused" when it receives a request pointing to the local machine. Its main task is to forward traffic to remote servers, so it may incorrectly process this local request, causing it to be discarded or lost, never reaching the Gradio server listening on the local machine.

That's why you can open it in your browser, but gradio_client fails! Browsers may have their own proxy rules or plugins that bypass local addresses, while Python's network requests are firmly intercepted by the proxy software.

Part 3: Best Practices: Solve the Problem Elegantly Without Closing the Proxy

Closing the proxy software every time is too troublesome. Fortunately, we have better methods.

This is a "set it and forget it" method. You need to tell your proxy software: "Please ignore all traffic accessing the local machine."

In the configuration file of your proxy software (such as Clash), find the rules section, add a direct (DIRECT) rule for local addresses, and ensure it is near the top of the rules list.

For example, in Clash's config.yaml, add:

yaml
rules:
  # ... Other rules ...
  - DOMAIN,localhost,DIRECT
  - IP-CIDR,127.0.0.0/8,DIRECT
  # ... Other rules ...

After saving and reloading the configuration, the problem is solved. Your proxy software will intelligently allow local traffic while continuing to proxy other network requests.

Option 2: Disable the System Proxy Option in the Proxy Software

As shown in the figure, disable it in Clash

Clear system proxy in v2ray

Option 3: Use the NO_PROXY Environment Variable (Temporary Solution)

If you just want to run the script temporarily, you can set an environment variable at runtime to tell the running program not to use a proxy.

  • Linux / macOS:
    bash
    export NO_PROXY="localhost,127.0.0.1"
    python your_client_script.py
  • Windows (CMD):
    cmd
    set NO_PROXY=localhost,127.0.0.1
    python your_client_script.py
  • Windows (PowerShell):
    powershell
    $env:NO_PROXY="localhost,127.0.0.1"
    python your_client_script.py

Summary: Ultimate Troubleshooting Checklist

When you encounter Could not fetch config again, check in the following order for maximum efficiency:

  1. [Primary Check] Have I turned on the system proxy mode of any VPN or network proxy? Try closing it or setting up a local direct connection rule.
  2. [Browser Test] Can I open http://127.0.0.1:7860 in the browser? (Confirm if the server is alive)
  3. [Verify Address] Is the URL in Client() exactly the same as the URL displayed when the server starts?
  4. [Check Environment] If using Docker, have I configured server_name="0.0.0.0" and port mapping -p?
  5. [Check Firewall] Is the system firewall or antivirus software blocking Python's network connection?

Hope this detailed guide can help you clear the obstacles and make your journey with gradio_client smooth from now on!