2009-02-23 14:19:43 -07:00
|
|
|
|
2017-02-21 13:15:51 -08:00
|
|
|
import treq
|
2009-02-23 14:19:43 -07:00
|
|
|
from twisted.internet import defer
|
2017-02-21 13:15:51 -08:00
|
|
|
from twisted.web.error import Error
|
2009-02-23 14:19:43 -07:00
|
|
|
|
2017-02-21 13:15:51 -08:00
|
|
|
@defer.inlineCallbacks
|
|
|
|
def do_http(method, url, **kwargs):
|
|
|
|
response = yield treq.request(method, url, persistent=False, **kwargs)
|
|
|
|
body = yield treq.content(response)
|
|
|
|
# TODO: replace this with response.fail_for_status when
|
|
|
|
# https://github.com/twisted/treq/pull/159 has landed
|
|
|
|
if 400 <= response.code < 600:
|
|
|
|
raise Error(response.code, response=body)
|
|
|
|
defer.returnValue(body)
|