推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
M4rs
V2EX  ›  Python

家人们, Python 在爬 https 的时候会出现一个少见的问题,是本地环境的问题吗?

  •  
  •   M4rs · Apr 21, 2021 · 3647 views
    This topic created in 2021 days ago, the information mentioned may be changed or developed.
    Exception has occurred: URLError
    <urlopen error unknown url type: https>
    File "D:\pachong\pachong.py", line 2, in <module>
    urllib.request.urlopen('https://baidu.com')

    报错代码如上

    在爬取 http 的网站是没有这个问题的,一到 https 就会报错。
    谷歌了很多,说需要配置这些:SSL 库也是有的(但是无法导入),openssl 库。 无果。
    大家怎么看?
    Supplement 1  ·  Apr 21, 2021
    安装 anaconda 后,问题解决。
    原因应该是系统环境问题,具体什么原因还未果。
    10 replies  •  2021-04-22 13:41:17 +08:00
    whileFalse
    whileFalse
    Apr 21, 2021
    1
    这是 python2 么。
    lusi1990
    lusi1990
    Apr 21, 2021
    2
    from urllib.request import urlopen

    resp = urlopen('https://baidu.com')
    print(resp.read())

    我这一点问题都没有,建议用 virtualenv 创建虚拟环境,再试试。Windows 推荐使用 conda
    M4rs
    M4rs
    OP
    Apr 21, 2021
    3
    @whileFalse python3.8
    M4rs
    M4rs
    OP
    Apr 21, 2021
    4
    @lusi1990 对的,同样的代码,一样报错,应该是环境问题,但是搜索无果,也重新配置了。我再想想
    lusi1990
    lusi1990
    Apr 21, 2021
    5
    @M4rs 用 conda 建个虚拟环境吧。不折腾
    superrichman
    superrichman
    Apr 21, 2021 via iPhone
    6
    编译 python 没有把 ssl 编进去,要重装 python
    M4rs
    M4rs
    OP
    Apr 21, 2021
    7
    @superrichman 重装过很多次,而且也试了几个版本,无果。也许是有什么神奇的问题吧。
    M4rs
    M4rs
    OP
    Apr 21, 2021
    8
    @lusi1990 正在尝试
    tomcats
    tomcats
    Apr 22, 2021
    9
    用 requests 库爬 https
    wunsch0106
    wunsch0106
    Apr 22, 2021
    10
    openssl 版本问题?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1480 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 23:23 · PVG 07:23 · LAX 15:23 · JFK 18:23
    ♥ Do have faith in what you're doing.