Skip to content

Commit ed2256c

Browse files
Compile FAQ to documentation markdown 🤖
1 parent 8134184 commit ed2256c

File tree

1 file changed

+173
-0
lines changed

1 file changed

+173
-0
lines changed
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# How to debug SSL communication issues?
2+
3+
| Date | Category |
4+
|------------|-------------|
5+
| 2023-10-24 15:55:24 | Simulation Troubleshoot |
6+
7+
8+
9+
10+
# How to debug SSL communication issues?
11+
12+
Users operating within corporate networks, through a VPN, or behind a proxy server may sometimes encounter SSL errors when running the `tidy3d` python client in their local machines. **Note you can always use the python client with [our cloud-hosted notebook server](https://tidy3d.simulation.cloud/).**
13+
14+
These errors can occur because the corporate network's security measures, intercepts, and re-encrypts HTTPS traffic.
15+
16+
A common error message looks like this:
17+
18+
```bash
19+
requests.exceptions.SSLError: HTTPSConnectionPool(host='tidy3d-api.simulation.cloud', port=443): Max retries exceeded with url: ... (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate ...')))
20+
```
21+
22+
Note that sometimes, SSL errors can also manifest as authentication errors, or communication timeout errors.
23+
24+
In this FAQ, we will overview some steps to help you debug and resolve this issue.
25+
26+
## Step 0: Windows quick fix
27+
Sometimes on Windows running the following will resolve the problem right away. Try this first:
28+
```bash
29+
pip install pip-system-certs
30+
```
31+
If this doesn't work, proceed with the rest of this guide.
32+
33+
## Step 1: The Recommended & Most Secure Solution
34+
35+
The most robust and secure solution is to have your IT department add the Tidy3D SSL certificate to your system's trust store. This allows your machine to verify our servers' identity correctly without disabling security features.
36+
37+
**Action**: Please ask your network administrator to whitelist the API endpoint `https://tidy3d-api.simulation.cloud` and install the following root certificate [https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/web/api/cacert.pem](https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/web/api/cacert.pem)
38+
39+
If these steps do not resolve your issue, please contact our support team and provide the logs from the commands you have tried.
40+
41+
42+
## Step 2: Verify Your Environment and Connectivity
43+
44+
Before changing any settings, let's make sure you can reach the Tidy3D servers.
45+
46+
**Test connectivity using `ping`**. This helps confirm if the issue is with SSL verification or basic network access. You should run these commands from your command line (Terminal, PowerShell, or the Anaconda Prompt).
47+
48+
* Test connection to the web server:
49+
50+
```bash
51+
○ → ping -c 3 tidy3d.simulation.cloud
52+
PING tidy3d.simulation.cloud (3.160.231.60) 56(84) bytes of data.
53+
64 bytes from server-3-160-231-60.mad53.r.cloudfront.net (3.160.231.60): icmp_seq=1 ttl=245 time=58.7 ms
54+
64 bytes from server-3-160-231-60.mad53.r.cloudfront.net (3.160.231.60): icmp_seq=2 ttl=245 time=77.9 ms
55+
64 bytes from server-3-160-231-60.mad53.r.cloudfront.net (3.160.231.60): icmp_seq=3 ttl=245 time=69.2 ms
56+
57+
58+
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
59+
rtt min/avg/max/mdev = 58.661/68.594/77.930/7.877 ms
60+
```
61+
62+
* Test connection to the API endpoints:
63+
64+
```bash
65+
○ → curl -X GET https://tidy3d-api.simulation.cloud
66+
{
67+
"error" : "Unauthorized",
68+
"detail" : "Access is denied",
69+
"code" : "401",
70+
"httpStatus" : "401 UNAUTHORIZED",
71+
"warning" : ""
72+
}
73+
```
74+
75+
**Expected output:** A `401 Unauthorized` error message. This is good news; it means you can reach our API server, and the problem is likely with authentication or SSL certificate verification.
76+
77+
Note that many networks can block ping messages so this is not a foolproof check.
78+
79+
## Step 3: Disable SSL Verification (Quick Workaround)
80+
81+
**As a temporary solution**, you can instruct `tidy3d` to bypass SSL certificate verification. This is not ideal for security but is useful for confirming the source of the problem.
82+
83+
This is done by setting the `TIDY3D_SSL_VERIFY` environment variable to `false`.
84+
85+
#### Setting the Environment Variable:
86+
87+
* **On Windows (in Command Prompt)**:
88+
89+
```bash
90+
set TIDY3D_SSL_VERIFY=false
91+
```
92+
93+
To set it permanently, use `setx TIDY3D_SSL_VERIFY false`.
94+
95+
* **On macOS or Linux (in a bash terminal)**:
96+
97+
```bash
98+
export TIDY3D_SSL_VERIFY="false"
99+
```
100+
101+
Note thet the user could run into unexpected server communication issues by disabling SSL. This is not recommended.
102+
103+
#### Verifying the Environment Variable:
104+
105+
**It is essential to ensure the variable is set correctly within the environment where you run your script.**
106+
107+
* **In your terminal**, run the following command.
108+
109+
* Windows: `echo %TIDY3D_SSL_VERIFY%`
110+
* macOS/Linux: `echo $TIDY3D_SSL_VERIFY`
111+
* The output should be `false`.
112+
113+
* **Inside your Python script**, add these lines to the top to see what value the script is reading:
114+
115+
```python
116+
import os
117+
print(f"TIDY3D_SSL_VERIFY is set to: {os.getenv('TIDY3D_SSL_VERIFY')}")
118+
```
119+
120+
When you run your script, you should see the confirmation printed. If you see `None` or an empty string, the variable was not set correctly in your current session.
121+
122+
## Step 4: Run a Diagnostic Script
123+
124+
If the issue persists, running a minimal script can help isolate the problem to the `requests` library, which `tidy3d` uses for communication.
125+
126+
1. Save the following code as a Python file (e.g., `test_connection.py`).
127+
2. Set the `TIDY3D_API_KEY` and `TIDY3D_SSL_VERIFY` environment variables in your terminal as shown in Step 2.
128+
3. Run the script with `python test_connection.py`.
129+
130+
131+
```python
132+
# test_connection.py
133+
import os
134+
import requests
135+
from tidy3d.web.core.constants import HEADER_APIKEY
136+
from tidy3d.web.core.environment import Env
137+
138+
def auth(req):
139+
"""Adds the API key to the request header."""
140+
# Ensure TIDY3D_API_KEY is set in your environment
141+
req.headers[HEADER_APIKEY] = os.getenv("TIDY3D_API_KEY")
142+
return req
143+
144+
# Let tidy3d's environment configuration read the SSL variable
145+
# It reads from the TIDY3D_SSL_VERIFY environment variable.
146+
ssl_verify_setting = Env.current.ssl_verify
147+
148+
print(f"API Endpoint: {Env.current.web_api_endpoint}")
149+
print(f"SSL Verification Enabled: {ssl_verify_setting}")
150+
151+
if not ssl_verify_setting:
152+
# Suppress the warning that will be printed for unverified requests
153+
requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning)
154+
print("InsecureRequestWarning suppressed.")
155+
156+
try:
157+
req = requests.Request("GET", f"{Env.current.web_api_endpoint}/apikey")
158+
auth(req)
159+
resp = requests.get(req.url, headers=req.headers, verify=ssl_verify_setting)
160+
161+
print(f"Response: {resp}")
162+
print(f"Status Code: {resp.status_code}")
163+
print(f"Response Content: {resp.content}")
164+
165+
except requests.exceptions.SSLError as e:
166+
print(f"\nCaught an SSLError. This is the core issue.\nDetails: {e}")
167+
168+
except Exception as e:
169+
print(f"\nAn unexpected error occurred: {e}")
170+
171+
```
172+
173+
With `TIDY3D_SSL_VERIFY` set to `false` and `TIDY3D_API_KEY` set correctly, the expected output is a `status code: 200` and content containing your API key. You will also see an `InsecureRequestWarning` if you don't suppress it.

0 commit comments

Comments
 (0)