_Goal:_ I want to print logs of the smart contract, like I do on web3.js, using web3.py.
On web3.js side, following code piece works:
var event = myContract.LogJob({}, {fromBlock:0, toBlock:'latest'});
event.watch(function(error, result) {
console.log(JSON.stringify(result));
});
But on the web3.py side I was not able to make it work. :( I have followed following documentation.
event_filter = myContract.eventfilter('LogJob', {'filter': {'arg1':10}})
Error I am having:
AttributeError: 'Contract' object has no attribute 'eventFilter'
I have also tried following line of code, but it did not worked as well:
event = myContract.call().LogJob({}, {'fromBlock':100, 'toBlock':110});
[Q] Am I doing something wrong? How could I fix this?

I'm going to guess that you're using the 3.x line since you're on python 2.7.
In that case you should be using the stable version of the docs: http://web3py.readthedocs.io/en/stable/ as latest is the 4.x release line.
I think you're looking for my_contract.on('TheEvent', ...) in the 3.x line. See: http://web3py.readthedocs.io/en/stable/contracts.html#web3.contract.Contract.on
cc @dylanjw and @carver
Would be good for us to try and figure out a practical way to have notes like "added in 4.0" like I've seen in django and the python standard library documentation.
let me know if this doesn't fix your issue and we'll get this re-opened and figured out.
@pipermerriam
Now I get a different error, I have tried:
transfer_filter = eBlocBroker.on('LogCluster', {'filter': {'_from': '0x6af0204187a93710317542d383a1b547fa42e705'}})
The error I have received:
Traceback (most recent call last):
File "getClusterInfo.py", line 53, in <module>
transfer_filter = eBlocBroker.on('LogCluster', {'filter': {'_from': '0x6af0204187a93710317542d383a1b547fa42e705'}})
File "/usr/local/lib/python2.7/dist-packages/web3/utils/decorators.py", line 13, in _wrapper
return self.method(obj, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/web3/contract.py", line 345, in on
argument_filter_names,
File "/usr/local/lib/python2.7/dist-packages/web3/contract.py", line 647, in _find_matching_event_abi
raise ValueError("No matching functions found")
ValueError: No matching functions found
Can you post the ABI for your contract (and verify that there is indeed an event with the name LogCluster.
Yes I verify that there is an event with the name LogCluster.
On web3.js side following code works:
var event = myContract.LogCluster({}, {fromBlock:0, toBlock:'latest'});
event.watch(function(error, result) {
console.log(JSON.stringify(result));
});
ABI: https://gist.github.com/avatar-lavventura/c45ad830700a9d19cd0e9c1ce417c380
Your last comment is the same as this issue: https://github.com/ethereum/web3.py/issues/699, and shows that our documentation needs to be fixed. Our example has _from in the filter arguments, that makes it seem like that is the way to filter for the emanating contract, rather than what it is, an argument specific to the example event.
Because your LogCluster event has no _from argument, the web3 abi lookup doesnt find an event abi that matches the argument and event name combination.
In other words, the filter argument dict can be used to match events with the given argument values. Based on your event ABI and example code, that might look like this:
transfer_filter = eBlocBroker.on('LogCluster', {'filter': {'clusterAddr': cluster_address}})
If you just want all logs emanating from that event, just delete the filter parameter.
transfer_filter = eBlocBroker.on('LogCluster')
Could this be help to fix the issue: https://ethereum.stackexchange.com/a/43471/4575
pip install --pre --upgrade web3
Could this be help to fix the issue: https://ethereum.stackexchange.com/a/43471/4575
Well, upgrading won't change the fact that you need to drop the _from argument from the filter.
But yes, you need the latest v4 for eventFilter.
Closing, since I believe everything is addressed. Please feel free to comment to carry on the conversation if you're still stuck.
I am still stuck and facing with some errors :( @carver @dylanjw
Following line returns: []. But on web3.js side it returns logs. On my smart contract I did not use the emit keyword, could it be the reason?
transfer_filter = eBlocBroker.on('LogCluster')
print(transfer_filter.get())
Following line:
transfer_filter = eBlocBroker.on('LogCluster', {'filter': {'clusterAddr': clusterAddress}})
print(transfer_filter.get())
returns:
Traceback (most recent call last):
File "getClusterInfo.py", line 54, in <module>
transfer_filter = eBlocBroker.on('LogCluster', {'filter': {'clusterAddr': clusterAddress}})
File "/usr/local/lib/python2.7/dist-packages/web3/utils/decorators.py", line 13, in _wrapper
return self.method(obj, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/web3/contract.py", line 345, in on
argument_filter_names,
File "/usr/local/lib/python2.7/dist-packages/web3/contract.py", line 647, in _find_matching_event_abi
raise ValueError("No matching functions found")
ValueError: No matching functions found
=> Can't we also state fromBlock to start reading events from specific blockNumber?
At this point, it seems like you'll be best off posting the source of a minimal, but complete, example to ethereum.stackexchange.com (that means the solidity source, the python that emits the event and that watches for it).
TY @carver I already did asked on ethereum.stackexchange.com (https://ethereum.stackexchange.com/q/43091/4575), I guess you responded.
Your latest issue has a different setup and a different error. Try asking a new question.
New question: https://ethereum.stackexchange.com/q/43642/4575 @carver
@dylanjw Is this error message normal?
transfer_filter = smartContract.on('LogCluster', {'filter': {'clusterAddr': clusterAddress}})
AttributeError: 'Contract' object has no attribute 'on'
@avatar-lavventura Have a look at the web3.py docs, specifically on filters and contracts. The contract class does not implement an "on" method, like you may be used to in web3.js (or js in general).
Callbacks are one pattern for building asynchronous programs. There are other patterns as well. Take a look at http://web3py.readthedocs.io/en/stable/filters.html#asynchronous where we give examples for how you might implement asynchronous filter polling in your code, if that is what you are after.
@dylanjw I just want to print the logs _synchronously_.
Following line seems working:
blockReadFrom = 1000;
my_filter = smartContract.eventFilter('LogName',{'fromBlock':int(blockReadFrom),'toBlock':'latest'});
print(my_filter.get_all_entries()[0].args['LogTypeName'])
Most helpful comment
cc @dylanjw and @carver
Would be good for us to try and figure out a practical way to have notes like "added in 4.0" like I've seen in django and the python standard library documentation.