Skip to content

Commit ace0522

Browse files
fix: add httpx[socks] dependency for SOCKS proxy support (#2664)
Co-authored-by: openhands <openhands@all-hands.dev>
1 parent 9040bb5 commit ace0522

3 files changed

Lines changed: 67 additions & 4 deletions

File tree

openhands-sdk/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies = [
1010
"fakeredis[lua]>=2.32.1", # Explicit dependency for docket/fastmcp background tasks
1111
"fastmcp>=3.0.0",
1212
"filelock>=3.20.1",
13-
"httpx>=0.27.0",
13+
"httpx[socks]>=0.27.0",
1414
"litellm==1.80.10",
1515
"pydantic>=2.12.5",
1616
"python-frontmatter>=1.1.0",
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""Tests for SOCKS proxy support (OpenHands/OpenHands-CLI#632).
2+
3+
When a user has SOCKS proxy env vars set (e.g. all_proxy=socks5://...),
4+
httpx needs the socksio package to handle SOCKS proxy connections.
5+
Without it, importing litellm (which creates an httpx.Client at module
6+
level) crashes at startup with ImportError.
7+
"""
8+
9+
import os
10+
import subprocess
11+
import sys
12+
13+
14+
def test_socksio_is_installed():
15+
"""Verify that socksio is installed as part of httpx[socks]."""
16+
import socksio # noqa: F401
17+
18+
19+
def test_httpx_socks_extra_available():
20+
"""Verify httpx can create a client when SOCKS proxy env vars are set."""
21+
import httpx
22+
23+
# Simulate a SOCKS proxy env var; the Client constructor should not raise
24+
# ImportError for socksio. We use a non-routable address so no real
25+
# connection is attempted.
26+
client = httpx.Client(proxy="socks5://127.0.0.1:19999")
27+
client.close()
28+
29+
30+
def test_import_with_socks_proxy_env():
31+
"""Ensure httpx can be imported and used when all_proxy is set to socks5."""
32+
env = os.environ.copy()
33+
env["all_proxy"] = "socks5://127.0.0.1:19999"
34+
env["https_proxy"] = "socks5://127.0.0.1:19999"
35+
36+
result = subprocess.run(
37+
[
38+
sys.executable,
39+
"-c",
40+
"import httpx; c = httpx.Client(); c.close(); print('ok')",
41+
],
42+
capture_output=True,
43+
text=True,
44+
env=env,
45+
)
46+
assert result.returncode == 0, (
47+
f"Import failed with SOCKS proxy env vars set:\n{result.stderr}"
48+
)
49+
assert "ok" in result.stdout

uv.lock

Lines changed: 17 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)