推荐学习书目
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
aiqier
V2EX  ›  Python

tornado 的异步请求如何实现模拟登录?

  •  
  •   aiqier · Jan 16, 2017 · 4085 views
    This topic created in 3414 days ago, the information mentioned may be changed or developed.

    之前写 python 的模拟客户端登录,都是使用 python 的 requests 库。因为这个库有 requests.session(),写模拟登录非常方便。

    但现在我的一个 tornado 异步服务,有一个模拟登录的需求。我需要用异步,所以只能用: tornado.httpclient.AsyncHTTPClient()之类的异步方式,不能用 requests 库。

    那么我应该如何用 tornado 的异步库来实现模拟登录的 session ?

    6 replies    2018-01-30 16:57:04 +08:00
    abc950309
        1
    abc950309  
       Jan 17, 2017
    看一下 trequests 吧,别人已经做好轮子了……
    自己写的话,没记错的话,连 Cookie 都要自己解析……
    aiqier
        2
    aiqier  
    OP
       Jan 17, 2017
    @abc950309 我咋没搜到这个东西。
    abc950309
        3
    abc950309  
       Jan 17, 2017
    @aiqier 请用 Google ……
    https://github.com/1stvamp/trequests
    可能有点老了,可以根据这个思路 fork 一个。
    tyl
        4
    tyl  
       Jan 17, 2017
    requests 的 session 无非就是帮你实现了方便的 cookie 管理,让你下次访问该网站的时候自动在 header 里面加上了它的 cookie , tornado 的每个请求都是异步的,所以感觉可以把每次请求获取到的 cookie 存到缓存(比如 redis )里面,每次进行下一步的请求时就可以先从缓存里面读 cookie 然后更新 header 。
    maze1024
        5
    maze1024  
       Jan 18, 2017
    aiohttp 也是异步的
    maodei
        6
    maodei  
       Jan 30, 2018
    @maze1024 aiohttp 是 python3.X 的。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2824 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 466ea39e · 44ms · UTC 06:02 · PVG 14:02 · LAX 23:02 · JFK 02:02
    ♥ Do have faith in what you're doing.