0

I have written following script to get Vin address from Vin txids.

#!/usr/bin/python
# -*- coding: utf-8 -*-
import requests,json
url="http://asd:asdf@localhost:2332"
payload={}
payload = {"jsonrpc":1,"id":"curltext"}
 txid= "10ff6ff5bdc73d7bb6d711c6896618a05479d061e67f576a0950328c1389035f"
addresses = []

payload["method"]="getrawtransaction"
payload["params"]=[txid,1]
response = requests.post(url,json.dumps(payload))
response =response.json()
response= response["result"]["vin"]

for data in response:
    raw_tx1=data["txid"]
    vout_int=data["vout"]
    payload["params"]=[raw_tx1,1]
    response_ = requests.post(url,json.dumps(payload))
    response_= response_.json()
    data_ =response_["result"]["vout"]
    for item in data_:
        if item["n"] == vout_int:
            json_data ={}
            json_data[item["scriptPubKey"]["addresses"][0]] = item["value"]
            addresses.append(json_data)

print addresses

for some txids i get proper o/p for example:

[{u'MKHWXiX9Xm37jdCM8EzWMWNRJPhuwUxWiN': 50.0},{u'MVTpa2h3DGFWxkcmEkYLv4cYGggVprjjDZ': 300.0}]

but for other its says

    response= response["result"]["vin"]
TypeError: 'NoneType' object has no attribute '__getitem__'

Why is it behaving like this? Isnt it supposed to have uniform output irrespective of txids? If my approach is wrong then how was i getting correct for some tx ids again?

1 Answer 1

1

That error means that either response or response['result'] is None which means that getrawtransaction is probably unable to find the transaction id that you are providing.

Before you try to read data from the response, make sure it isn't None and actually has a result.

1
  • i guess issue was because i didnt mentionled txindex flag in my .conf file. Now when i put txindex=1 it seems to be working fine Commented May 3, 2018 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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