推荐学习书目
› 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 · 3485 views
    This topic created in 1983 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
        1
    whileFalse  
       Apr 21, 2021
    这是 python2 么。
    lusi1990
        2
    lusi1990  
       Apr 21, 2021
    from urllib.request import urlopen

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

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