Reputation: 1627
I've tried dir(), but the commands just return messages like this:
<bound method HTTPResponse.begin of <http.client.HTTPResponse object at 0x00E9DEF0>>
which I'm afraid I don't know how to interpret.
Disclaimer: I haven't used Python much at all, so this may be a really stupid question. Please be gentle.
Thanks!
Upvotes: 1
Views: 5525
Reputation: 45
HTTPResponse.read()
function can be used to get the body of the HTTPResponse. The function HTTPresponse.read()
reads the http.client.HTTPResponse
object and returns the response body. More about it can be found in Python docs https://docs.python.org/3/library/http.client.html#httpresponse-objects
response = urllib.request.urlopen(some_request)
body = response.read()
Note:urllib.request.urlopen(some_request)
returns HTTP response object
Upvotes: 1
Reputation: 81
You can print the contents of A HTTPResponse object line by line like this
# Get the object from a url
url = 'https://www.example.com'
response_object = urllib.request.urlopen(url)
# Print the contents line by line
for line in response_object:
print(line)
Upvotes: 1
Reputation: 799230
Methods, just as functions, must be followed by parens (()
), optionally containing arguments, in order to invoke them.
someobj.somemeth()
Upvotes: 3