fix: use host.docker.internal for Transmission RPC connection
This commit is contained in:
@@ -10,17 +10,15 @@ router = APIRouter(prefix="/api/transmission", tags=["transmission"])
|
||||
def get_session_id() -> str:
|
||||
"""Get Transmission RPC session ID"""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["ssh", "nas", "curl -si -u 'admin:admin' 'http://127.0.0.1:9091/transmission/rpc' 2>&1 | grep -i 'X-Transmission-Session-Id:' | cut -d' ' -f2 | tr -d '\\r'"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
shell=True,
|
||||
timeout=5
|
||||
)
|
||||
session_id = result.stdout.strip()
|
||||
if not session_id:
|
||||
raise Exception("Failed to get session ID")
|
||||
return session_id
|
||||
with httpx.Client(timeout=5.0) as client:
|
||||
response = client.get(
|
||||
"http://host.docker.internal:9091/transmission/rpc",
|
||||
auth=("admin", "admin")
|
||||
)
|
||||
session_id = response.headers.get("X-Transmission-Session-Id")
|
||||
if not session_id:
|
||||
raise Exception("Failed to get session ID from headers")
|
||||
return session_id
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Failed to get Transmission session ID: {str(e)}")
|
||||
|
||||
@@ -37,7 +35,7 @@ def transmission_rpc(method: str, arguments: Dict[str, Any] = None) -> Dict[str,
|
||||
# Use httpx to make the request
|
||||
with httpx.Client(timeout=10.0) as client:
|
||||
response = client.post(
|
||||
"http://100.78.131.124:9091/transmission/rpc",
|
||||
"http://host.docker.internal:9091/transmission/rpc",
|
||||
json=payload,
|
||||
auth=("admin", "admin"),
|
||||
headers={"X-Transmission-Session-Id": session_id}
|
||||
|
||||
Reference in New Issue
Block a user