python2.7でrequest使ってhtml downloadする

以下のコードをpython2.7ベースではエラーになるので

import urllib.request


# 「走れメロス」を青空文庫からダウンロード
url = 'http://www.aozora.gr.jp/cards/000035/files/1567_14913.html'
html = ''

with urllib.request.urlopen(url) as response:
    html = response.read().decode('shift_jis')

print(html)

pip install requests
を実施後
以下のコードに直して 動いた。

# -*- coding: utf-8 -*-
import requests


# 「走れメロス」を青空文庫からダウンロード
url = 'http://www.aozora.gr.jp/cards/000035/files/1567_14913.html'
html = ''

with requests.get(url) as response:
    response.encoding = response.apparent_encoding
    html = response.text.encode(response.encoding)
print(html)

参考
http://ohke.hateblo.jp/

ついでに
pyOoepnSSLのインストール備忘録

https://slproweb.com/products/Win32OpenSSL.html

Win32 OpenSSL v1.1.0f
をdownloadする(ご利用環境によって異なります)。
Win32OpenSSL-1_1_0f.exe
を実行してインストールする。

> set INCLUDE=C:\OpenSSL-Win32\include;%INCLUDE%
> set LIB=C:\OpenSSL-Win32\lib;%LIB%
> pip install cryptography

を実行する

pip install pyOpenSSL

で成功した。

参考
https://stackoverflow.com/questions/45089805/pip-install-cryptography-in-windows

あと
asn1crypto==0.23.0
ndg-httpsclient==0.4.3
もインストールした。
これで
python scriptの
requests.post
によるOpenssl関連エラーがおきる場合は
python2.7系だと
python2.7.8ではエラーが起きており
python2.7.9に入れなおすと
現象回避した。