推荐学习书目
› 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
Livid
402.83D
565.12D
V2EX  ›  Python

Requests 有可能像 PyCURL 那样拿到各个阶段的耗时么:DNS 时间,连接时间,下载时间……

  •  
  •   Livid ·
    PRO
    · Nov 3, 2013 · 5574 views
    This topic created in 4748 days ago, the information mentioned may be changed or developed.
    4 replies  •  1970-01-01 08:00:00 +08:00
    9hills
    9hills
    Nov 3, 2013
    1
    我瞅了瞅requests的代码,貌似不能。requests自己实现了一个urllib3做底层

    PyCURL是怎么拿到的?
    est
    est
    Nov 3, 2013
    2
    可以拿到,需要hack。

    DNS时间 -> socket 不直接 connect(), 先 gethostbyname(),计时得到

    连接时间 -> socket 去connect() 直连IP用个计时

    请求时间 -> socket 去send()计时

    返回时间 -> socket.recv() 计时
    lovesky
    lovesky
    Nov 3, 2013
    3
    @est 我想这里的Requests应该指的是这个:Requests: HTTP for Humans

    http://www.python-requests.org/en/latest/
    https://pypi.python.org/pypi/requests
    est
    est
    Nov 3, 2013
    4
    @lovesky 知道。。。python里边的对象都是可以hook的。


    import socket

    socket = 1
    import requests

    然后你试试还能用requests不?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5088 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 07:41 · PVG 15:41 · LAX 23:41 · JFK 02:41
    ♥ Do have faith in what you're doing.