qpandalite.network_utils module#

Network utilities for proxy detection and connectivity testing.

This module provides functions for: - Detecting system proxy settings - Testing proxy connectivity - Testing IBM Quantum connectivity with or without proxy

qpandalite.network_utils.check_proxy_connectivity(proxy_url, test_url='https://www.googleapis.com', timeout=10.0)[源代码]

Check if a proxy is reachable and can connect to a test URL.

参数:
  • proxy_url (str) -- The proxy URL to test (e.g., 'http://proxy.example.com:8080').

  • test_url (str) -- URL to test connectivity through the proxy (default: Google APIs).

  • timeout (float) -- Connection timeout in seconds (default: 10.0).

返回:

True if the proxy is reachable, False otherwise.

返回类型:

bool

备注

This function performs a basic TCP connection check to the proxy host and port. It does not perform an actual HTTP CONNECT request or verify that the proxy can reach the test URL.

示例

>>> is_available = check_proxy_connectivity(
...     "http://proxy.example.com:8080"
... )
>>> print(f"Proxy available: {is_available}")
qpandalite.network_utils.detect_system_proxy()[源代码]

Detect system proxy settings from environment variables.

Checks for both uppercase and lowercase environment variable names: - HTTP_PROXY / http_proxy - HTTPS_PROXY / https_proxy

Uppercase variants take precedence over lowercase ones.

返回:

dict with keys 'http' and 'https', values are proxy URLs or None.

返回类型:

dict[str, str | None]

示例

>>> proxies = detect_system_proxy()
>>> print(proxies)
{'http': 'http://proxy.example.com:8080', 'https': None}
qpandalite.network_utils.test_ibm_connectivity(token=None, proxy=None, timeout=30.0)[源代码]

Test connectivity to IBM Quantum services.

参数:
  • token (str | None) -- IBM Quantum API token. If None, tries to load from environment.

  • proxy (dict[str, str] | str | None) -- Proxy configuration. Can be: - None: uses system proxy settings - str: proxy URL (used for both http and https) - dict: with 'http' and/or 'https' keys

  • timeout (float) -- Request timeout in seconds (default: 30.0).

返回:

{

'success': bool, 'message': str, 'proxy_used': dict | str | None, 'response_time_ms': float | None,

}

返回类型:

dict with connectivity test results

示例

>>> result = test_ibm_connectivity(
...     token="my_api_token",
...     proxy={"https": "http://proxy.example.com:8080"}
... )
>>> print(result["success"])