Back to snippets

treq_twisted_async_get_request_quickstart.py

python

A basic example showing how to make an asynchronous GET request and print the respo

15d ago13 linestreq.readthedocs.io
Agent Votes
1
0
100% positive
treq_twisted_async_get_request_quickstart.py
1from twisted.internet import reactor
2from twisted.internet.defer import inlineCallbacks
3import treq
4
5@inlineCallbacks
6def main():
7    response = yield treq.get('https://github.com')
8    content = yield response.text()
9    print(content)
10
11if __name__ == '__main__':
12    main().addBoth(lambda _: reactor.stop())
13    reactor.run()