Forum Discussion

Kate's avatar
Kate
Contributor
7 years ago
Solved

Empty response (request in python)

I need to retrieve some data using GET request.

Here is a part of my code:

my_conn = http.client.HTTPConnection("mydomain.com")
my_conn.request('GET', '/blahblahblah/.....server_type=35') 
  response = my_conn.getresponse()
  if response.status != 200:
    Log.Error('Did not get info')
  else:
    Log.Message(response.read())

I run the same piece of code twice - for server type 35 and for server type 36.
If I run that code in Sublime3 - I get all the data printed out for both server types.

But in TestComplete I got an empty response for both of them.

I added .decode('UTF-8') to response.read()

It helped for one request, but did not help for the second one. It is still empty...

 

Any suggestions?

 


  • Kate wrote:

     

    It looks like TestComplete prints my data to the log with WHITE font color.

     


     

    Nice feature :)

     

    What if you will pass all content to the Additional Information tab of the Log?

     

    Log.Message("Some title", response.read())

7 Replies

  • baxatob's avatar
    baxatob
    Community Hero

    Can you show what data is returned by both responses?

    • Kate's avatar
      Kate
      Contributor

       

      It should return smth like that:

      {"oops-oops-prod-01":{"server_type":"35","name":"oops-oops-prod-01","oops_ip":"111.111.111.11","confirmed":"0"},"oops-oops-prod-02":{"server_type":"35","name":"oops-oops-prod-02","oops_ip":"111.111.111.11","confirmed":"0"},

      and so on.

       

      In TestComplete I get empty row in the Log.

      • baxatob's avatar
        baxatob
        Community Hero

        Hm... Your code works on my side (with my url) if I use str() method.

         

        You can try to use a higher level library like urllib or even requests

         

        Also you can play with timeout argument. A little chance that your default timeout setting is too small.

         

         

        http.client.HTTPConnection('your_domain', timeout=10)

         

         

        But first of all check that you do not receive an empty response.