Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SSL errors #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

longmathemagician
Copy link

Fixes #8 & #40 by passing Mozilla's root certs to urllib. As far as I can tell this is the idiomatic solution for recent Python versions. Requires the installation of python-certifi (pip install certifi), which should probably be included in the fix for #36.

@jmmelko
Copy link

jmmelko commented Dec 19, 2023

This fix is becoming urgent as we have permanent SSL certification errors with our newest python installations (3.12).
However the provided fix triggers a timeout error:

Une exception s'est produite : URLError <urlopen error [WinError 10060] Une tentative de connexion a échoué car le parti
connecté n’a pas répondu convenablement au-delà d’une certaine durée ou une connexion établie a échoué car l’hôte de
connexion n’a pas répondu> TimeoutError: [WinError 10060] Une tentative de connexion a échoué car le parti connecté n’a pas
répondu convenablement au-delà d’une certaine durée ou une connexion établie a échoué car l’hôte de connexion n’a pas
répondu During handling of the above exception, another exception occurred:


urllib.error.URLError: <urlopen error [WinError 10060] Une tentative de connexion a échoué car le parti connecté n’a pas
répondu convenablement au-delà d’une certaine durée ou une connexion établie a échoué car l’hôte de connexion n’a pas
répondu>

@jmmelko
Copy link

jmmelko commented Dec 19, 2023

Hi,

your solution will conflict with the proxy. I suggest the following:

def requestOpener(url):
    
    context = ssl.create_default_context(cafile=certifi.where()) # Uses a SSL certificate, mandatory since Python 3.9.x
    handler = urllib2.HTTPSHandler(context=context)
    # Proxy handling # https://stackoverflow.com/questions/1450132/proxy-with-urllib2
    if VARIABLES['PROXY']:
        print('Using proxy '+str(VARIABLES['PROXY']))
        proxy = urllib2.ProxyHandler(VARIABLES['PROXY'])
    else:
        proxy = urllib2.ProxyHandler({})
    
    opener = urllib2.build_opener(proxy, handler)
    urllib2.install_opener(opener)     
    
    return urllib2.urlopen(url)  

Feel free to improve this, pull a new request, and force the developer to at last update his code

@rde-girl
Copy link

rde-girl commented Apr 10, 2024

I am getting the same error and have not been able to resolve even by connecting through a hotspot. @jmmelko thank you for providing a solution. I am just curious with where it should be implemented? It looks close to the structure in the function queryHITRAN. Thank you for your help, The solution from @longmathemagician did not solve my particular issue unfortunately.

URLError: <urlopen error [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

Cell In[20], line 1
[sim_1f_up,sim_2f_up,sim_4f_up,sim_2f_1f_up,sim_4f_2f_up,T_arr,PH2O_arr,delta_nuC_arr] = wms.generate_lookup(T_range,PH2O_range,delta_nuC_range,L,nu0,i0_up,i2_up,bl_coef[4],bl_coef[8],phi_range)

File ~\OneDrive\Documents\hapi\WMS_functions.py:999 in generate_lookup
hpi.fetch('temp1',1,1,border_wing[0],border_wing[1],ParameterGroups=['160-char'])

File ~\OneDrive\Documents\hapi\hapi.py:4900 in fetch
---

File ~\OneDrive\Documents\hapi\hapi.py:2875 in queryHITRAN
raise Exception('Failed to retrieve data for given parameters.')

Exception: Cannot connect to http://hitran.org. Try again or edit GLOBAL_HOST variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot connect to hitran
3 participants