0

I'm not very experienced with Python and I'm pretty sure this is just a syntax issue.

I'm trying to use the monerod daemon RPC /get_transactions method from here.

I have no problem getting the examples here to work and this (non-json) RPC call works fine as well:

import requests
import json
def main():
    response = requests.post("http://localhost:18081/getheight")
    r=response.json()
    print(r)
if __name__ == "__main__":
    main()

However, whenever I try to use /get_transactions like this:

    transactionList = ["d6e48158472848e6687173a91ae6eebfa3e1d778e65252ee99d7515d63090408"]
    PARAMS = {'txs_hashes' : transactionList ,
              'decode_as_json' : True}
    myTransactions = requests.post("http://localhost:18081/get_transactions", params = PARAMS)
    print(myTransactions)

It always returns an error such as:

<Response [404]>

I'm pretty sure I'm just passing it the parameters incorrectly but I've tried a bunch of different permutations and checked the requests documentation and still can't get it to work.

Thanks!

1

You are so very close.

Just change params = PARAMS to json = PARAMS and it will work.

From the requests documentation:

Using the json parameter in the request will change the Content-Type in the header to application/json.

And to get the response text, use:

print(myTransactions.text)

Or to get the response as a json object:

print(myTransactions.json())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.