Unidata / siphon

Siphon - A collection of Python utilities for retrieving atmospheric and oceanic data from remote sources, focusing on being able to retrieve data from Unidata data technologies, such as the THREDDS data server.
https://unidata.github.io/siphon
BSD 3-Clause "New" or "Revised" License
216 stars 75 forks source link

SSL Error with Certificate in catalog.py #281

Open eroesler opened 5 years ago

eroesler commented 5 years ago

Please redirect or absolve the issue if it violates the contributing guidelines

I've been working to get a tutorial python code from the Unidata site called GOES_aircraft.py, working from my corporation's computer. In the script, there are two function calls to retrieve data. When I execute this script, it fails with SSL errors related to the certificate verify failing. (note: This looks like a common problem for people running python scripts behind corporate firewalls.)

I've managed to figure-out a work-around for the first function, 'get_plane_data' by adding / altering these two lines: ..... context = ssl._create_unverified_context() with urllib.request.urlopen(endpoint_url, context=context) as f: .....

When it comes to the second function, however, 'get_goes_image', I am not sure how to bypass the certificate check in the TDSCatalog call. I've looked through the catalog.py script for a flag for a solution, but am unable to identify where to begin.

Help or advice is greatly appreciated.

dopplershift commented 5 years ago

I appreciate the report. Does this answer on Stack Overflow help? I think it should work if you pass verify=False to set_session_options. Even better, you should be able to then use:

with siphon.http_util.session_manager.urlopen(endpoint_url) as f:
...

Using functions that start with _ from a library (like _create_unverfied_context) is kind of a no-no, as they're not guaranteed to exist in future versions.

eroesler commented 5 years ago

@dopplershift : Thank you for the response. Here's what's happening after trying some StackOverFlow

I've added to the top:

 from siphon.http_util import session_manager

commented-out in get_plane_data,

 #with urllib.request.urlopen(endpoint_url) as f:

and replaced it with

session_manager.set_session_options(verify=False)      
with siphon.http_util.session_manager.urlopen(endpoint_url) as f:

I think I'm missing something because this now thows an error:

with siphon.http_util.session_manager.urlopen(endpoint_url) as f:
NameError: name 'siphon' is not defined

Even though using _create_unverfied_context is naughty, I did get the get_plane_data function to work.

The function, get_goes_image, is still failing. I am not sure how to correct this yet still. I've tried adding the recommended commands to the more simple example, Basic_Usage.py, and still get the proxy errors.

dopplershift commented 5 years ago

What you have is not quite valid use of Python imports. You can either do:

from siphon.http_util import session_manager
...
with session_manager.urlopen(endpoint_url) as f:

OR

import siphon.http_util
...
with siphon.http_util.session_manager.urlopen(endpoint_url) as f:

(The ... are not literal but represent elided code.)

kahemker commented 4 years ago

I have a similar problem while working on my corporate network. The only solution that I have found is with any HTTP GET request, I must pass specific set of headers and turn off SSL verify. When I am just performing a simple request with the requests module directly, I can set these options to whatever I need. However, I have found siphon quite useful for acquiring MET data, so I did a little digging through the source and found an easy way to also pass the same arguments through here.

Check out this PR to see which lines I modified. #303

Exactly which settings you need to get this working on your proxy are probably different than mine, but hopefully this minor code change to siphon will allow you to get running at work.