<small id='dLp8Q'></small><noframes id='dLp8Q'>

    <i id='dLp8Q'><tr id='dLp8Q'><dt id='dLp8Q'><q id='dLp8Q'><span id='dLp8Q'><b id='dLp8Q'><form id='dLp8Q'><ins id='dLp8Q'></ins><ul id='dLp8Q'></ul><sub id='dLp8Q'></sub></form><legend id='dLp8Q'></legend><bdo id='dLp8Q'><pre id='dLp8Q'><center id='dLp8Q'></center></pre></bdo></b><th id='dLp8Q'></th></span></q></dt></tr></i><div id='dLp8Q'><tfoot id='dLp8Q'></tfoot><dl id='dLp8Q'><fieldset id='dLp8Q'></fieldset></dl></div>
    <legend id='dLp8Q'><style id='dLp8Q'><dir id='dLp8Q'><q id='dLp8Q'></q></dir></style></legend>
        <bdo id='dLp8Q'></bdo><ul id='dLp8Q'></ul>

      <tfoot id='dLp8Q'></tfoot>
    1. 如何测量 Python 请求 POST 请求的服务器响应时间

      How to measure server response time for Python requests POST-request(如何测量 Python 请求 POST 请求的服务器响应时间)
          <tbody id='QinUJ'></tbody>

          <bdo id='QinUJ'></bdo><ul id='QinUJ'></ul>
          <i id='QinUJ'><tr id='QinUJ'><dt id='QinUJ'><q id='QinUJ'><span id='QinUJ'><b id='QinUJ'><form id='QinUJ'><ins id='QinUJ'></ins><ul id='QinUJ'></ul><sub id='QinUJ'></sub></form><legend id='QinUJ'></legend><bdo id='QinUJ'><pre id='QinUJ'><center id='QinUJ'></center></pre></bdo></b><th id='QinUJ'></th></span></q></dt></tr></i><div id='QinUJ'><tfoot id='QinUJ'></tfoot><dl id='QinUJ'><fieldset id='QinUJ'></fieldset></dl></div>
          <legend id='QinUJ'><style id='QinUJ'><dir id='QinUJ'><q id='QinUJ'></q></dir></style></legend>
          <tfoot id='QinUJ'></tfoot>

                <small id='QinUJ'></small><noframes id='QinUJ'>

                本文介绍了如何测量 Python 请求 POST 请求的服务器响应时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我像这样创建 requests POST 请求,我在其中指定超时阈值:

                I create requests POST-requests like this, where I specify timeout threshold:

                response = requests.post(url, data=post_fields, timeout=timeout)

                但是,为了确定一个好的"阈值,我想提前对服务器响应时间进行基准测试.

                However, to determine a "good" threshold value, I would like to benchmark the server response time in advance.

                如何计算服务器的最小和最大响应时间?

                How do I compute the minimum and maximum response times for the server?

                推荐答案

                requests.post()(和requests.get() etc.) 有一个名为 elapsed 的属性,它提供发送 Request 和收到 Response 之间的时间差.要以秒为单位获取增量,请使用 total_seconds() 方法:

                The Response object returned by requests.post() (and requests.get() etc.) has a property called elapsed, which provides the time delta between the Request was sent and the Response was received. To get the delta in seconds, use the total_seconds() method:

                response = requests.post(url, data=post_fields, timeout=timeout)
                print(response.elapsed.total_seconds())
                

                注意 requests.post() 是一个同步操作,这意味着它阻塞直到收到 Response.

                Note that requests.post() is a synchronous operation, which means that it blocks until the Response is received.

                这篇关于如何测量 Python 请求 POST 请求的服务器响应时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                How to extend Python class init(如何扩展 Python 类初始化)
                What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                Initialize list with same bool value(使用相同的布尔值初始化列表)
                setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                  <bdo id='x0Ree'></bdo><ul id='x0Ree'></ul>
                • <legend id='x0Ree'><style id='x0Ree'><dir id='x0Ree'><q id='x0Ree'></q></dir></style></legend>
                      <tfoot id='x0Ree'></tfoot>

                        <tbody id='x0Ree'></tbody>
                      <i id='x0Ree'><tr id='x0Ree'><dt id='x0Ree'><q id='x0Ree'><span id='x0Ree'><b id='x0Ree'><form id='x0Ree'><ins id='x0Ree'></ins><ul id='x0Ree'></ul><sub id='x0Ree'></sub></form><legend id='x0Ree'></legend><bdo id='x0Ree'><pre id='x0Ree'><center id='x0Ree'></center></pre></bdo></b><th id='x0Ree'></th></span></q></dt></tr></i><div id='x0Ree'><tfoot id='x0Ree'></tfoot><dl id='x0Ree'><fieldset id='x0Ree'></fieldset></dl></div>

                          <small id='x0Ree'></small><noframes id='x0Ree'>