π examples/common/diag_connect.py¶
Tiny network sanity check for your GRPC_SERVER β from DNS all the way to gRPC TLS channel readiness. Perfect for answering: βIs the network broken or is it my code?β
π§ Plain English¶
Runs four checks in order and stops at the first failure:
- DNS β resolve host.
- TCP β open a raw TCP socket to
host:port. - TLS β perform the handshake (SNI =
HOST). - gRPC β create a secure aio channel and await
channel_ready().
Prints OK / FAIL β¦ for each step.
The script does not set a process exit code. Read the text output.
π Source¶
PyMT5/examples/common/diag_connect.py
Deps: stdlib + grpc (aio channel).
βοΈ Environment¶
Single env var (with default):
GRPC_SERVER=mt5.mrpc.pro:443
Quick ways to set GRPC_SERVER¶
PowerShell (Windows):
$env:GRPC_SERVER = "your.host.com:443"
CMD (Windows):
set GRPC_SERVER=your.host.com:443
Bash (Linux/macOS):
export GRPC_SERVER=your.host.com:443
βΆοΈ How to run¶
Pick the command that matches where you run it from.
A. From the parent of the PyMT5/ package folder:
python -m PyMT5.examples.common.diag_connect
B. From inside the PyMT5/ package folder:
python -m examples.common.diag_connect
C. Directly by path:
python PyMT5/examples/common/diag_connect.py
# or, if your CWD is PyMT5/:
python examples/common/diag_connect.py
If you use a virtual env, replace
pythonwith.venv/Scripts/python(Windows) or.venv/bin/python(Unix).
π¨οΈ Sample output¶
[1] DNS resolve myhostβ¦
OK: ['203.0.113.10', '203.0.113.12']
[2] TCP connect myhost:443β¦
OK
[3] TLS handshake myhost:443β¦
OK
[4] gRPC channel_ready (TLS) myhost:443β¦
OK (channel ready)
π§― Troubleshooting (by step)¶
[1] FAIL DNS β host typo, DNS override (hosts/VPN/adbocker), DNS server down.
β Check:
nslookup your.host.com/dig your.host.com.
[2] FAIL TCP β port closed by server/firewall, corporate proxy/DPI, routing issue.
β Check:
telnet host 443/Test-NetConnection -Port 443.
[3] FAIL TLS β wrong SNI/cert, MITM proxy without trusted root, bad system clock.
β Check:
openssl s_client -connect host:443 -servername host.
[4] FAIL gRPC TLS β service is HTTP(S) but not gRPC/HTTP2, ALPN quirks, requires special creds/mTLS.
β Ensure it is a gRPC endpoint and intermediates are valid.
π‘ Notes¶
channel_ready()waits 10s. In highβlatency nets you may bump the timeout in code if needed.CERTIFICATE_VERIFY_FAILEDoften means a corporate TLS proxy. Install the proxy CA certificate into your OS store (no code change required).- Some proxies/firewalls break ALPN/TLS β step [3] OK, step [4] fails.
Next¶
If all four steps are OK, infra is fine. Jump to root examples/ (market/history/streaming/trading). If a step fails, use the Troubleshooting hints to fix the corresponding network layer first.
π§± Slow and steady: DNS β TCP β TLS β gRPC.