Home How do I get the response text from a treq request?
Reply: 0

How do I get the response text from a treq request?

user934
1#
user934 Published in June 23, 2018, 8:00 am

I am trying to get started with some example code of the treq library, to little avail. While it is easy to get the status code and a few other properties of the response to the request, getting the actual text of the response is a little more difficult. The print_response function available in this example code is not present in the version that I have:

from twisted.internet.task import react
from _utils import print_response

import treq


def main(reactor, *args):
    d = treq.get('http://httpbin.org/get')
    d.addCallback(print_response)
    return d

react(main, [])

Here is the traceback:

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    from _utils import print_response
ModuleNotFoundError: No module named '_utils'

I am not really sure where to go from here...any help would be greatly appreciated.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.308001 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO