Skip to content

πŸ”Œ 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:

  1. DNS β†’ resolve host.
  2. TCP β†’ open a raw TCP socket to host:port.
  3. TLS β†’ perform the handshake (SNI = HOST).
  4. 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 python with .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_FAILED often 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.