Proxy Scheme Not Supported | Generated by AI
The error indicates that the httpx
library, used by the openai
client in your gitmessageai.py
script, is attempting to configure a proxy with the URL socks://127.0.0.1:7891/
, but the scheme socks
is not supported or recognized, resulting in a ValueError: Unknown scheme for proxy URL
. This suggests that a proxy configuration is being picked up from your environment or code, and it’s using an unsupported SOCKS proxy scheme.
Let’s break down where the proxy might come from and how to fix it.
Where Is the Proxy Coming From?
The proxy configuration (socks://127.0.0.1:7891/
) is likely being sourced from one of the following places:
- Environment Variables
- The
httpx
library automatically checks for proxy settings in environment variables likeHTTP_PROXY
,HTTPS_PROXY
,ALL_PROXY
, or their lowercase equivalents (http_proxy
,https_proxy
,all_proxy
). - A value like
socks://127.0.0.1:7891/
suggests a SOCKS proxy (common for tools like Shadowsocks or VPNs) was set in one of these variables. - To check if these variables are set, run the following in your terminal:
env | grep -i proxy
Look for variables like
HTTP_PROXY=socks://127.0.0.1:7891
orHTTPS_PROXY=socks://127.0.0.1:7891
.
- The
- System-Wide Proxy Settings
- If you’re using a Linux system, proxy settings might be configured globally (e.g., in
/etc/environment
,/etc/profile
, or your shell configuration like~/.bashrc
,~/.zshrc
, or~/.profile
). - Check these files for lines like:
export HTTP_PROXY="socks://127.0.0.1:7891" export HTTPS_PROXY="socks://127.0.0.1:7891"
- You can view these files with:
cat ~/.bashrc | grep -i proxy cat ~/.zshrc | grep -i proxy cat /etc/environment | grep -i proxy
- If you’re using a Linux system, proxy settings might be configured globally (e.g., in
- Proxy Configuration in a Proxy Tool
- The address
127.0.0.1:7891
is commonly used by proxy or VPN tools like Shadowsocks, V2Ray, or Clash, which often default to SOCKS5 proxies on ports like 7890 or 7891. - If you’ve installed or configured such a tool, it might have automatically set environment variables or system proxy settings.
- The address
- Explicit Proxy in Code
- Though less likely, your
gitmessageai.py
script or a library it uses might be explicitly configuring a proxy. Since the error occurs inhttpx
, check if your script passes a proxy to theOpenAI
client orhttpx
client. - Search your script for terms like
proxy
,proxies
, orhttpx.Client
:grep -r -i proxy /home/lzwjava/bin/gitmessageai.py
- Though less likely, your
- Python Library Configuration
- Some Python libraries (e.g.,
requests
orhttpx
) might inherit proxy settings from a configuration file or a previous setup. However,httpx
primarily relies on environment variables or explicit code.
- Some Python libraries (e.g.,
Why Is socks://
Causing an Issue?
- The
httpx
library (used byopenai
) does not natively support thesocks
scheme (SOCKS4/SOCKS5 proxies) unless additional dependencies likehttpx-socks
are installed. - The error
Unknown scheme for proxy URL
occurs becausehttpx
expects proxies with schemes likehttp://
orhttps://
, notsocks://
.
How to Fix the Issue
You have two options: remove or bypass the proxy if it’s not needed, or support the SOCKS proxy if you intend to use it.
Option 1: Remove or Bypass the Proxy
If you don’t need a proxy for the DeepSeek API, you can disable or bypass the proxy configuration.
- Unset Environment Variables
- If the proxy is set in environment variables, unset them for your session:
unset HTTP_PROXY unset HTTPS_PROXY unset ALL_PROXY unset http_proxy unset https_proxy unset all_proxy
- To make this permanent, remove the corresponding
export
lines from~/.bashrc
,~/.zshrc
,/etc/environment
, or other shell configuration files.
- If the proxy is set in environment variables, unset them for your session:
- Run Script Without Proxy
- Temporarily run your script without proxy settings:
HTTP_PROXY= HTTPS_PROXY= ALL_PROXY= python3 /home/lzwjava/bin/gitmessageai.py
- If this works, the proxy was the issue.
- Temporarily run your script without proxy settings:
- Bypass Proxy in Code
- Modify your
gitmessageai.py
script to explicitly disable proxies in theOpenAI
client:from openai import OpenAI import httpx def call_deepseek_api(prompt): api_key = os.getenv("DEEPSEEK_API_KEY") if not api_key: raise ValueError("DEEPSEEK_API_KEY environment variable is not set") client = OpenAI( api_key=api_key, base_url="https://api.deepseek.com", http_client=httpx.Client(proxies=None) # Disable proxies ) # Your API call logic here response = client.chat.completions.create( model="deepseek", # Replace with correct model messages=[{"role": "user", "content": prompt}] ) return response.choices[0].message.content
- Setting
proxies=None
ensureshttpx
ignores any environment proxy settings.
- Modify your
Option 2: Support the SOCKS Proxy
If you need to use the SOCKS proxy (e.g., for accessing the DeepSeek API through a VPN or proxy server), you must add SOCKS support to httpx
.
- Install
httpx-socks
- Install the
httpx-socks
package to enable SOCKS4/SOCKS5 proxy support:pip install httpx-socks
- This extends
httpx
to handlesocks://
andsocks5://
schemes.
- Install the
- Update Your Code
- Modify your script to use the SOCKS proxy explicitly:
from openai import OpenAI import httpx from httpx_socks import SyncProxyTransport def call_deepseek_api(prompt): api_key = os.getenv("DEEPSEEK_API_KEY") if not api_key: raise ValueError("DEEPSEEK_API_KEY environment variable is not set") # Configure SOCKS5 proxy proxy_transport = SyncProxyTransport.from_url("socks5://127.0.0.1:7891") client = OpenAI( api_key=api_key, base_url="https://api.deepseek.com", http_client=httpx.Client(transport=proxy_transport) ) # Your API call logic here response = client.chat.completions.create( model="deepseek", # Replace with correct model messages=[{"role": "user", "content": prompt}] ) return response.choices[0].message.content
- Replace
socks5://
withsocks4://
if your proxy uses SOCKS4.
- Modify your script to use the SOCKS proxy explicitly:
- Verify Proxy Server
- Ensure the proxy server at
127.0.0.1:7891
is running. If you’re using a tool like Clash or Shadowsocks, check its status:netstat -tuln | grep 7891
- If no process is listening on port 7891, start your proxy tool or correct the port in the proxy URL.
- Ensure the proxy server at
Additional Debugging Steps
- Check Proxy Tool Configuration
- If you’re using a proxy tool like Clash or Shadowsocks, verify its configuration file (e.g.,
~/.config/clash/config.yaml
) to confirm it’s set to use127.0.0.1:7891
for SOCKS5. - Ensure the tool is running and accessible.
- If you’re using a proxy tool like Clash or Shadowsocks, verify its configuration file (e.g.,
- Test Proxy Connectivity
- Test the proxy with a tool like
curl
(requirescurl
built with SOCKS support):curl --socks5 127.0.0.1:7891 https://api.deepseek.com
- If this fails, the proxy server is either down or misconfigured.
- Test the proxy with a tool like
- Log Proxy Usage
- Add logging to your script to confirm which proxy is being used:
import logging logging.basicConfig(level=logging.DEBUG)
- Add logging to your script to confirm which proxy is being used:
Recommended Fix
If you don’t need the proxy, the simplest fix is to disable it by unsetting environment variables and running:
HTTP_PROXY= HTTPS_PROXY= ALL_PROXY= python3 /home/lzwjava/bin/gitmessageai.py
If you need the proxy, install httpx-socks
and update your code to use SyncProxyTransport
as shown above.