cancel
Showing results for 
Search instead for 
Did you mean: 

Empty response (request in python)

SOLVED
Highlighted
Contributor

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Empty response (request in python)


@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())

View solution in original post

7 REPLIES 7
Highlighted
Community Hero

Re: Empty response (request in python)

Can you show what data is returned by both responses?

Highlighted
Contributor

Re: Empty response (request in python)

 

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.

Highlighted
Community Hero

Re: Empty response (request in python)

Try: Log.Message(str(response.read()))
Highlighted
Contributor

Re: Empty response (request in python)

I tried str()

No success

Highlighted
Community Hero

Re: Empty response (request in python)

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.

Highlighted
Contributor

Re: Empty response (request in python)

I am absolutely sure I do not get empty response - it works perfectly outside of TC.

 

It looks like TestComplete prints my data to the log with WHITE font color. I navigated to the row and it expanded like its' content is longer that the field's widths. I copied/pasted to notepad and all the data was there!

 

But I faced a new issue with another request.

I get only 5 response headers, while there are much more... And again, it works fine outside of TestComplete.

 

 

Highlighted
Community Hero

Re: Empty response (request in python)


@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())

View solution in original post

New Here?
Join us and watch the welcome video:
Top Kudoed Authors