'Message' object is not callable

Asked by kyle

Hi there,

I am trying to append an NDEF record to my tag and I am running into an odd error, this might be due to my Python knowledge but a point in the right direction would be great, this is the problematic part of the code:

def connected(tag):
    freq = 2500
    dur = 500
    winsound.Beep(freq, dur)
    record1 = nfc.ndef.Record('urn:nfc:wkt:U', 'Video', 'https://www.youtube.com/watch?v=FIRT7lf8byw')
    msg = tag.ndef.message()
    msg.append(record1)
    ndefdata = tag.ndef.message.pretty() if tag.ndef else 'No NDEF'

The error I get:

TypeError: 'Message' object is not callable

I've spent hours reading the documentation and I'm not sure what is wrong here, any help is greatly appreciated!

Thanks,

Kyle

Question information

Language:
English Edit question
Status:
Answered
For:
nfcpy Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#1

The 'tag' is an instance of class nfc.ndef.Tag (https://nfcpy.readthedocs.io/en/latest/modules/tag.html#nfc.tag.Tag) which has an attribute named 'ndef' (https://nfcpy.readthedocs.io/en/latest/modules/tag.html#nfc.tag.Tag.ndef). The 'ndef' attribute is either None or an instance of class Tag.NDEF (https://nfcpy.readthedocs.io/en/latest/modules/tag.html#nfc.tag.Tag.NDEF). That in turn has, amongst others, an attribute called 'message' (https://nfcpy.readthedocs.io/en/latest/modules/tag.html#nfc.tag.Tag.NDEF.message). And 'message' finally yields the class nfc.ndef.Message instance that was decoded from the tag. You'll just work with the class members or assign a new nfc.ndef.Message instance to tag.ndef.message.

The shorter version is that you must remove the brackets () after tag.ndef.message when you make a reference to it by the name of 'msg'. But you should also not forget to test for 'tag.ndef is not None' before working with the message attribute.

Can you help with this problem?

Provide an answer of your own, or ask kyle for more information if necessary.

To post a message you must log in.