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

urllib.request.urlopen alias isn't functional for https #167

Open
Liz4v opened this issue Sep 18, 2015 · 4 comments
Open

urllib.request.urlopen alias isn't functional for https #167

Liz4v opened this issue Sep 18, 2015 · 4 comments

Comments

@Liz4v
Copy link

Liz4v commented Sep 18, 2015

This works fine:

Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib2 import urlopen                                           
>>> urlopen('https://google.ca')                                          
<addinfourl at 140299620351008 whose fp = <socket._fileobject object at 0x7f9a0f352050>>
>>> _.read()[:100]
'<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-CA"><head><meta cont'

Great! But then this fails:

Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import future.standard_library
>>> future.standard_library.install_aliases()
>>> from urllib.request import urlopen
>>> urlopen('https://google.ca')
(…)
future.backports.urllib.error.URLError: <urlopen error unknown url type: https>
>>> future.__version__
'0.15.2'

But 3 is fine too:

Python 3.4.0 (default, Jun 19 2015, 14:20:21) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib.request import urlopen
>>> urlopen('https://google.ca')
<http.client.HTTPResponse object at 0x7f5cdbb295c0>
>>> _.read()[:100]
b'<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-CA"><head><meta cont'

What's going on?

@Liz4v
Copy link
Author

Liz4v commented Sep 18, 2015

I'm using a workaround: leandigo/pyoneall@3b4adae

@Liz4v
Copy link
Author

Liz4v commented Feb 21, 2016

Bump!

@mjschultz
Copy link

We ran into a similar issue yesterday and I looked into it today. I'm not sure if there is something better than your workaround because the SSL library built into python 2.7.9 broke backward compatibility (for critical security reasons) which is what ends up causing the error.

In both python core and futures the http.client detects availability of SSL and HTTPS during module import, this is done through importing the ssl module. future also checks for SSLContext (the change introduced in 2.7.9 from backporting ssl from 3.x). If this can't be imported SSL is disabled and you can't make HTTPS connections.

It is conceivable that future could detect this and do some workaround to use the HTTPSConnection in pre-2.7.9 pythons, but I'm not sure that's worth it because of the security ramifications.

@Liz4v
Copy link
Author

Liz4v commented Aug 10, 2016

Thank you for your clarifications, @mjschultz.

Does that mean that after making my code work for Python 2.7.<9 (which is the one I happened to have handy) broke it for 2.7.>=9?

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

No branches or pull requests

3 participants