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

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

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

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

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

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

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

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

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


    import socket

    socket = 1
    import requests

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