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
zy8595208
V2EX  ›  Python

Python aiohttp 需要 http/2 支持,怎么办?

  •  
  •   zy8595208 · 2018-10-15 15:00:45 +08:00 · 3810 次点击
    这是一个创建于 1991 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近写一个爬虫程序,一直用 aiohttp 用的好好的,突然有一天模拟登陆不正常了 查了半天发现是网站换了 http2,所有 http1.1 协议的操作请求都 403 了. 找了半天才发现现在 python 的库基本没什么支持 http2 的,就一个 hyper 可以在 client 端发送 http2 请求. 可这货也是很久不更新了,很多功能不支持,连在 https 上 proxy 都不支持,而且功能少的可怜,很难用. 现在我想请教一下各位,有没有什么好的办法

    8 条回复    2018-10-15 15:26:36 +08:00
    cnilnhf
        1
    cnilnhf  
       2018-10-15 15:04:09 +08:00 via Android
    思路是,http2 应该有降级模式,不可能只强制使用 http2 协议连接,或许能解决你的问题。
    reus
        2
    reus  
       2018-10-15 15:04:35 +08:00
    换 go
    LokiSharp
        3
    LokiSharp  
       2018-10-15 15:06:19 +08:00
    requests 手动导入证书就行了 aiohttp 应该也可以的
    zy8595208
        4
    zy8595208  
    OP
       2018-10-15 15:08:09 +08:00
    @cnilnhf 网页页面 http1.1 可以请求打开查看,但是所有的 API 操作请求,都强制 http2 了.
    zy8595208
        5
    zy8595208  
    OP
       2018-10-15 15:09:14 +08:00
    @LokiSharp 证书和 http 协议版本有关系吗
    LokiSharp
        6
    LokiSharp  
       2018-10-15 15:13:34 +08:00
    @zy8595208 #5
    https://docs.aiohttp.org/en/stable/client_advanced.html#ssl-control-for-tcp-sockets
    看这里,默认是没有导入证书的所以不支持 https 手动指定一个证书就行了
    zy8595208
        7
    zy8595208  
    OP
       2018-10-15 15:17:13 +08:00
    @LokiSharp 现在不是 https 的问题,是被爬的网站必须使用 http/2 协议才能正常模拟登陆操作. 但是 aiohttp 现在还不支持 http/2 协议
    LokiSharp
        8
    LokiSharp  
       2018-10-15 15:26:36 +08:00
    诶,这个站用不支持 h2 的浏览器不会降级么?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1735 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:38 · PVG 00:38 · LAX 09:38 · JFK 12:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.