pythonredditprawbitcoind

Getting "<function get_balance at 0x7f85fff6a4c0>" when trying to send balance with praw and bitcoinrpc


I am trying to make a cryptocurrency tipbot for Reddit in python. I am trying to see if I can communicate with BitcoinAPI and return stuff like balance. My bot should have commented the balance but just commented this:

<function get_balance at 0x7f85fff6a4c0>

What does this even mean?

This is my code:

import praw
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException

# Authenticate with Reddit
reddit = praw.Reddit(
    client_id='',
    client_secret='',
    user_agent='',
    username='',
    password=''
)

reddit.validate_on_submit = True

# Print the username of the bot
print(reddit.user.me())

# TODO: Collect this data
#def getinboxdata(inboxdata):
# for item in reddit.inbox.all(limit=None):
#    print(repr(item))

def get_balance(address):
    rpc_connection = AuthServiceProxy("http://%s:%s@127.0.0.1:22555" % ('user', 'pass'))
    get_balance = rpc_connection.getbalance()
    return get_balance # This will print the balance

for item in reddit.inbox.unread(limit=None):
    if item.body == '+bunkertip':
        print('Bunkertip!')
        item.reply(get_balance)
        item.mark_read()
     

Solution

  • You're passing the function get_balance to item.reply. You need to call get balance and pass the result to item.reply. E.G.

    item.reply(get_balance())