def eth_request_from_db(method, args):
    try:
        url = "http://%s:%s" % (ETH_URL, ETH_PORT)
        request_template = '''{"id":"1","method":"%s","params":%s}'''
        args_j = json.dumps(args)

        data_to_send = request_template % (method, args_j)
        #print data_to_send
        agent = Agent(reactor)
        body = BytesProducer(data_to_send)
        d = agent.request(b'POST', url,
                          Headers({'Content-Type': ['application/json']}),
                          body)

        def cbResponse(response):
            # print('Response received')
            d = readBody(response)
            return d

        def cbErrResponse(response):
            return None

        d.addCallback(cbResponse)
        d.addErrback(cbErrResponse)
        #response = requests.request("POST", url, data=data_to_send, headers=headers)
        return d
    except Exception, ex:
        print "tttttt", ex
예제 #2
0
def eth_request(method, args):
    url = "http://%s:%s/rpc" % (ETH_URL, ETH_PORT)
    request_template = '''{"jsonrpc":"2.0","id":"1","method":"%s","params":%s}'''
    args_j = json.dumps(args)

    data_to_send = request_template % (method, args_j)
    headers = {
        'content-type': "application/x-www-form-urlencoded"
    }
    agent = Agent(reactor)
    body = BytesProducer(data_to_send)
    d = agent.request(
        b'POST',
        url,
        Headers({'User-Agent': ['Twisted Web Client Example']}),
        body)

    def cbResponse(response):
        #print('Response received')
        d = readBody(response)
        return d

    d.addCallback(cbResponse)




    #response = requests.request("POST", url, data=data_to_send, headers=headers)
    return d
예제 #3
0
from twisted.internet import reactor
from twisted.web.client import Agent
from twisted.web.http_headers import Headers

from bytesprod import BytesProducer

agent = Agent(reactor)
body = BytesProducer(b"hello, world")
d = agent.request(
    b"POST",
    b"http://httpbin.org/post",
    Headers(
        {
            "User-Agent": ["Twisted Web Client Example"],
            "Content-Type": ["text/x-greeting"],
        }
    ),
    body,
)


def cbResponse(ignored):
    print("Response received")


d.addCallback(cbResponse)


def cbShutdown(ignored):
    reactor.stop()
예제 #4
0
 def post(self, url, body={}, headers={}):
     if not headers:
         raise Exception('Missing headers')
     request = BytesProducer(json.dumps(body))
     d = agent.request('POST', url, Headers(headers), request)
     return d