Skip to content

Commit

Permalink
Option to disable SSL checks
Browse files Browse the repository at this point in the history
  • Loading branch information
hannorein committed Feb 13, 2025
1 parent 830acf9 commit 69b93d0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion rebound/horizons.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

INITDATE = None

# If this variable is set to "unverified" then the SSL context for API requests does not check certificates.
SSL_CONTEXT = None

def quote(text):
return "'{}'".format(text)
Expand Down Expand Up @@ -57,7 +59,17 @@ def api_request(particle, datestart, dateend, plane):
}
url = HORIZONSBASEURL + urlencode(get_params)
# don't use a context manager for python2 compatibility
f = urlopen(url)

if SSL_CONTEXT == "unverified":
import ssl
ssl_context = ssl._create_unverified_context()
else:
ssl_context = None
try:
f = urlopen(url,context=ssl_context)
except Exception as e:
raise RuntimeError("An error occured while accessing NASA HORIZONS. If this is a SSL certificate issue, you can try disabling the certificate verification by setting rebound.horizons.SSL_CONTEXT = 'unverified'.") from e

if "pyodide" in sys.modules:
body = f.read()
else:
Expand Down

0 comments on commit 69b93d0

Please sign in to comment.