I'm writing my first agent plugin...

I've been reading through the code on other agents on Github, trying to understand them enough to write one of my own. I have the following code:

 

def GetXML(url, cache_time=CACHE_1MONTH):

    tgdb_dict = None

    try:
        tgdb_dict = XML.ObjectFromURL(url, sleep=2.0, headers={‘Accept’: ‘application/xml’}, cacheTime=cache_time)
    except:
        Log(‘Error fetching XML from The Games DB.’)

    return tgdb_dict

########################################################################################################################

class TGDbAgent(Agent.Movies):

    name = ‘TheGamesDB’
    languages = [
        Locale.Language.English,
    ]
    primary_provider = True

    def search(self, results, media, lang, manual):
        
        tgdb_dict = GetXML(url=TGDB_GAME_SEARCH % (String.Quote(media.name), String.Quote(media.source)))

This however, fails with the following:

 

2015-01-11 04:01:16,807 (10e28d000) :  CRITICAL (agentkit:939) - Exception in the search function of agent named 'TheGamesDB', called with keyword arguments {'openSubtitlesHash': '97ef9c143f8150f1', 'name': 'Magician', 'platform': 'Nintendo Entertainment System (NES)', 'year': None, 'filename': '%2FUsers%2Fjohn%2FGames%2FMagician%2Ezip', 'source': 'Nintendo Entertainment System (NES)', 'plexHash': '95efa0733005291f3420933d05bd0c5e42275780', 'duration': '-1', 'id': '297904'} (most recent call last):
  File "/Users/john/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/api/agentkit.py", line 930, in _search
    agent.search(results, media, lang, manual)
  File "/Users/john/Library/Application Support/Plex Media Server/Plug-ins/TheGamesDB.bundle/Contents/Code/__init__.py", line 50, in search
    tgdb_dict = GetXML(url=TGDB_GAME_SEARCH % (String.Quote(media.name), String.Quote(media.source)))
  File "/Users/john/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/api/agentkit.py", line 626, in __getattr__
    return object.__getattr__(self, name)
AttributeError: type object 'object' has no attribute '__getattr__'

My code is very similar (if mangled and simplified) to what's in TheMovieDatabase.plugin. What does it find objectionable? I've had to switch from the JSON to XML, but that class also has a ObjectFromURL() method.

 

What am I doing wrong?

 

If you work with XML, the correct method is XML.ElementFromURL() which returns an XML tree (whereas JSON.ObjectFromURL returns an object/dict).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.