LoginSignup
1
0

More than 3 years have passed since last update.

ChromebookのcrostiniでPython3のrequestsとBeautifulSoupを使う時の設定

Last updated at Posted at 2020-02-15

はじめに

以前、Python3でスクレイピングしてみた(Python3とBeautifulSoup使って図書館で借りた本をスクレイピング - Qiita)けど、環境変わってもう一度試してみたら動かなかった。設定変更したら動いたので、その時のメモを残す。

環境構築

Google Chrome OS
Version 80.0.3987.89 (Official Build) beta (64-bit)
$ python3 --version
Python 3.5.3
$ sudo apt-get install python3-pip
$ pip3 --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.5)
$ sudo apt-get install python3-bs4
$ sudo apt-get install python3-requests

$ pip3 list
beautifulsoup4 (4.5.3)
requests (2.12.4)

参考にしたサイト↓
Python3.4以降のrequests対応 - Qiita

試したこと

普通に実行するとエラーがでる。

$ python3 scrape.py 
request
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/util/ssl_.py", line 308, in ssl_wrap_socket
    context.load_verify_locations(ca_certs, ca_cert_dir)
ssl.SSLError: unknown error (_ssl.c:3172)

(省略)

検索したら、このサイトがヒットした。
Python requests library can't make HTTPS connections (was: Apache certbot error) - Help - Let's Encrypt Community Support

ここに書かれてるSolved by:に書かれてるコマンドを試してみた。

$ cat /etc/ssl/certs/ca-certificates.crt
$ sudo update-ca-certificates
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...

done.
done.
$ cat /etc/ssl/certs/ca-certificates.crt 
-----BEGIN CERTIFICATE-----
(省略)
-----END CERTIFICATE-----

このあと、実行しなおしたらうまくいった。
CAの証明書が入ってなかったみたい。
公開鍵的なもの?
自分で仮想環境とか立ち上げるとデフォルト入ってないっぽい。しらんかった。ここらへん苦手。とりあえず、動いてよかった。

参考サイト↓
Ubuntu では ca-certificates パッケージで CA 証明書をインストールできるぞ - ひだまりソケットは壊れない
認証局 (CA:Certification Authority)とは?|GMOグローバルサイン【公式】

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0