0

I have installed python3.7 in ubuntu 14. Below is the process I followed

  1. Downloaded python 3.7
  2. ./configure
  3. sudo make
  4. sudo make install

Now I am running the follwoing code

from urllib.request import urlopen
resp = urlopen('http://github.com')
print(resp.read())

But it is giving the following errors on console:

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    resp = urlopen('https://github.com')
  File "/usr/local/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/lib/python3.7/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/usr/local/lib/python3.7/urllib/request.py", line 548, in _open
    'unknown_open', req)
  File "/usr/local/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python3.7/urllib/request.py", line 1387, in unknown_open
    raise URLError('unknown url type: %s' % type)`enter code here`
urllib.error.URLError: <urlopen error unknown url type: https>

Could someone please help me on this.

3
  • 3
    try resp = urlopen('https://github.com') - notice https Commented Dec 28, 2018 at 10:42
  • I tried that snippet of code and it game me no error. Strange. Commented Dec 28, 2018 at 10:43
  • The code you wrote looks fine. At least for me there is no error as well. Perhaps, you should check your environment. Is it not better to install from apt? - like: sudo apt-get install python3 ? Commented Dec 28, 2018 at 11:03

2 Answers 2

1

The reason for error is that your Python is configured and built without SSL support and when github.com redirects from http to https URL, you see this error: unknown url type: https.

Check your configure log and you'll see messages about no support for SSL detected.

The solution is install all required dependencies (in this case it is libssl-dev or something very similar) and re-configure and re-build Python from source.

Sign up to request clarification or add additional context in comments.

Comments

0

Try to use requests.get() function by importing the requests library. It is working fine on my side on python 2.7

import requests

r = requests.get('https://www.facebook.com/')
print type(r)
print r.status_code 
print r.headers
print r.headers['content-type']

Output :

    <class 'requests.models.Response'>
    200
    {'X-XSS-Protection': '0', 'X-Content-Type-Options': 'nosniff', 'Content-Encoding': 'gzip', 'Transfer-Encoding': 'chunked', 'Set-Cookie': 'fr=1my64VtKmpcYv2gSs..BcJgcK.TG.AAA.0.0.BcJgcK.AWXA3lHz; expires=Thu, 28-Mar-2019 11:20:42 GMT; Max-Age=7776000; path=/; domain=.facebook.com; secure; httponly, sb=CgcmXH47CJp-Qfmz1uyl_6eC; expires=Sun, 27-Dec-2020 11:20:42 GMT; Max-Age=63072000; path=/; domain=.facebook.com; secure; httponly', 'Strict-Transport-Security': 'max-age=15552000; preload', 'Vary': 'Accept-Encoding', 'X-FB-Debug': 'eP7JRcFDBbaRkLwVBGwHxDrySoaxLgW0z5eCGJibzcznQNszHVs/m0Vhh9v1i6aX5ri+bMmwpbbFnL4fCNNMPQ==', 'Connection': 'keep-alive', 'Pragma': 'no-cache', 'Cache-Control': 'private, no-cache, no-store, must-revalidate', 'Date': 'Fri, 28 Dec 2018 11:20:42 GMT', 'X-Frame-Options': 'DENY', 'Content-Type': 'text/html; charset="utf-8"', 'Expires': 'Sat, 01 Jan 2000 00:00:00 GMT'}
    text/html; charset="utf-8"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.