V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2021-04-21 16:29:29 +08:00 · 2135 次点击
    这是一个创建于 1093 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 库。 无果。
    大家怎么看?
    第 1 条附言  ·  2021-04-21 17:05:29 +08:00
    安装 anaconda 后,问题解决。
    原因应该是系统环境问题,具体什么原因还未果。
    10 条回复    2021-04-22 13:41:17 +08:00
    whileFalse
        1
    whileFalse  
       2021-04-21 16:40:50 +08:00
    这是 python2 么。
    lusi1990
        2
    lusi1990  
       2021-04-21 16:45:05 +08:00
    from urllib.request import urlopen

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

    我这一点问题都没有,建议用 virtualenv 创建虚拟环境,再试试。Windows 推荐使用 conda
    M4rs
        3
    M4rs  
    OP
       2021-04-21 16:45:38 +08:00
    @whileFalse python3.8
    M4rs
        4
    M4rs  
    OP
       2021-04-21 16:46:46 +08:00
    @lusi1990 对的,同样的代码,一样报错,应该是环境问题,但是搜索无果,也重新配置了。我再想想
    lusi1990
        5
    lusi1990  
       2021-04-21 16:48:33 +08:00
    @M4rs 用 conda 建个虚拟环境吧。不折腾
    superrichman
        6
    superrichman  
       2021-04-21 16:49:25 +08:00 via iPhone
    编译 python 没有把 ssl 编进去,要重装 python
    M4rs
        7
    M4rs  
    OP
       2021-04-21 16:55:53 +08:00
    @superrichman 重装过很多次,而且也试了几个版本,无果。也许是有什么神奇的问题吧。
    M4rs
        8
    M4rs  
    OP
       2021-04-21 16:56:02 +08:00
    @lusi1990 正在尝试
    tomcats
        9
    tomcats  
       2021-04-22 09:48:13 +08:00
    用 requests 库爬 https
    wunsch0106
        10
    wunsch0106  
       2021-04-22 13:41:17 +08:00
    openssl 版本问题?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1131 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 18:27 · PVG 02:27 · LAX 11:27 · JFK 14:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.