Python built-in urllib module does not support HTTPS protocol resolution

Source: Internet
Author: User
Tags install openssl ldap python script

The Django site uses Django_cas to access SSO (Single sign-on system), logs on after configuration is complete, and throws "Urlopen Error unknown URL Type:https" exception. Source discovery is python the built-in urllib module does not support the HTTPS protocol.

>>> Import Urllib
>>> urllib.urlopen (' http://www.baidu.com ')
<addinfourl at 269231456 whose FP = <socket._fileobject object at 0xff98250>>
>>> urllib.urlopen (' https://www.baidu.com ')
Traceback (most recent):
File "<stdin>", line 1, in <module>
File "/usr/local/python27/lib/python2.7/urllib.py", line +, in Urlopen
return Opener.open (URL)
File "/usr/local/python27/lib/python2.7/urllib.py", line 204, in open
Return Self.open_unknown (fullurl, data)
File "/usr/local/python27/lib/python2.7/urllib.py", line 216, in Open_unknown
Raise IOError, (' url error ', ' unknown URL type ', type)
IOError: [Errno URL error] Unknown URL type: ' HTTPS '

Python's built-in urllib module does not support the HTTPS protocol because it does not compile and install Python before installing an SSL library similar to OpenSSL, so that Python does not support SSL

Because I'm using a CentOS system, so install Openssl-devel.
sudo yum install Openssl-devel

Then recompile python
./configure (optional, because it has been configured before, it is OK to follow the previous configuration, and it is best to compile the installation by the previous configuration to avoid relying on the libraries need to recompile the installation. )
Make
Make install

>>> Import Urllib
>>> urllib.urlopen (' https://www.baidu.com ')

Did not report the same mistake again.

Before recompiling python after installing Openssl-devel, there is also the need to edit the Setup.dist file in the Modules folder.
Modify
# Socket Module helper for SSL support; You must comment out of the other
# socket line above, and possibly edit the SSL variable:
#SSL =/usr/local/ssl
#_ssl _ssl.c \
#-duse_ssl-i$ (SSL)/include-i$ (SSL)/INCLUDE/OPENSSL \
#-l$ (SSL)/lib-lssl-lcrypto
For
# Socket Module helper for SSL support; You must comment out of the other
# socket line above, and possibly edit the SSL variable:
Ssl=/usr/local/ssl
_ssl _ssl.c \
-duse_ssl-i$ (SSL)/include-i$ (SSL)/INCLUDE/OPENSSL \
-l$ (SSL)/lib-lssl-lcrypto

But the actual test does not seem to need to modify the file, compile time can automatically compile the SSL library into Python.

It is also important to note that after recompiling the installation of Python, the executable file name (possibly a connection file) may run Python or old Python, because the executable file name is not connected to the new Python executable. So run python with the latest Python executable file name or a connection to that name.

recompiling the installation of Python may result in the need to recompile the Django,mysqldb,pycrypto,python-ldap,django-auth-ldap,django_cas,django_cas, Pymongo and so on some columns depend on the Python module. Pay special attention to this.

Python initiates a Get and POST request to PHP http://www.linuxidc.com/Linux/2014-10/107903.htm

The second edition of Python core programming. (Wesley J. Chun). [HD PDF Chinese] http://www.linuxidc.com/Linux/2013-06/85425.htm

A detailed description of the Python development technology. (Zhou Wei, Zongjie). [HD PDF scan + with book video + code] http://www.linuxidc.com/Linux/2013-11/92693.htm

Python script gets Linux system Information http://www.linuxidc.com/Linux/2013-08/88531.htm

Using Python to build desktop algorithmic trading research environment in Ubuntu http://www.linuxidc.com/Linux/2013-11/92534.htm

A brief history of Python language development http://www.linuxidc.com/Linux/2014-09/107206.htm

detailed description of Python : please click here
Python : please click here.

This article permanently updates the link address : http://www.linuxidc.com/Linux/2014-12/110452.htm

Python built-in urllib module does not support HTTPS protocol resolution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.