推荐学习书目
› 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 · Oct 15, 2018 · 5417 views
    This topic created in 2902 days ago, the information mentioned may be changed or developed.

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

    8 replies  •  2018-10-15 15:26:36 +08:00
    cnilnhf
        1
    cnilnhf  
       Oct 15, 2018 via Android
    思路是,http2 应该有降级模式,不可能只强制使用 http2 协议连接,或许能解决你的问题。
    reus
        2
    reus  
       Oct 15, 2018
    换 go
    LokiSharp
        3
    LokiSharp  
       Oct 15, 2018
    requests 手动导入证书就行了 aiohttp 应该也可以的
    zy8595208
        4
    zy8595208  
    OP
       Oct 15, 2018
    @cnilnhf 网页页面 http1.1 可以请求打开查看,但是所有的 API 操作请求,都强制 http2 了.
    zy8595208
        5
    zy8595208  
    OP
       Oct 15, 2018
    @LokiSharp 证书和 http 协议版本有关系吗
    LokiSharp
        6
    LokiSharp  
       Oct 15, 2018
    @zy8595208 #5
    https://docs.aiohttp.org/en/stable/client_advanced.html#ssl-control-for-tcp-sockets
    看这里,默认是没有导入证书的所以不支持 https 手动指定一个证书就行了
    zy8595208
        7
    zy8595208  
    OP
       Oct 15, 2018
    @LokiSharp 现在不是 https 的问题,是被爬的网站必须使用 http/2 协议才能正常模拟登陆操作. 但是 aiohttp 现在还不支持 http/2 协议
    LokiSharp
        8
    LokiSharp  
       Oct 15, 2018
    诶,这个站用不支持 h2 的浏览器不会降级么?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   915 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 19:25 · PVG 03:25 · LAX 12:25 · JFK 15:25
    ♥ Do have faith in what you're doing.