-1

The following is not my code, but code I have to work with...

class MediaRoot:
  def __init__(self, type):
    self.name = ''
    self.year = None
    self.type = type
    self.parts = []
    self.subtitles = []
    self.thumbs = []
    self.arts = []
    self.trailers = []
    self.released_at = None
    self.display_offset = 0
    self.source = None
    self.themes = []

class Movie(MediaRoot):
  def __init__(self, name, year=None):
    MediaRoot.__init__(self,'Movie')
    self.name = name
    self.year = year
    self.guid = None

I have an object named "media" of type Movie, and I can work with its name and year attributes and do all the standard manipulations. I also know that there is a value stored in "source" that I'd very much like to access, but whenever I try it it blows up on me with the following error:

  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__'

Is this attribute just forever out of reach?

John O
  • 4,863
  • 8
  • 45
  • 78
  • Do you have an example of the code doing the accessing? Is the access code inside your plugin? – spirulence Jan 21 '15 at 05:06
  • The object is passed into my plugin by a mechanism I don't understand (new to Python). I'm just doing media.year or media.name, nothing fancy... when I try media.source though it barfs. – John O Jan 21 '15 at 05:16
  • @spirulence It's interesting to note that I get the same error for an attrib I know does not exist... so maybe I'm mistaken about the nature of the object I've been given. – John O Jan 21 '15 at 05:19

2 Answers2

0

Your MediaRoot object isn't subclassed from object, and thus doesn't have the __getattr__ method like Python objects usually do. Try this:

class MediaRoot(object):

spirulence
  • 701
  • 3
  • 11
  • @JohnO, then you should report the horrible bug "upstream" to whoever CAN fix it, and explain to your boss or customer why the constraint of being unable to fix the broken code they force you to work with makes solution impossible. Back when I spent a few years free-lancing, I had mastered the art of delivering such unwelcome messages!-) – Alex Martelli Jan 21 '15 at 05:02
0

You have...:

class MediaRoot:

in Python 2, unless you have __metaclass__ = type at global level, this is an old-style class (which nobody should use any more!) -- it needs to be

class MediaRoot(object):

If, as you say, you can't fix this error, I don't think there's a remedy.

The code in agentkit.py actually shown in your traceback is problematic too, but MediaRoot being an old-style class is your first problem.

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395
  • I don't have a choice about Python 2. I'm working on a plugin for Plex. Gotta use whatever they use. I don't even have much in the way of documentation, had to dig the Media.py file out of a bundle, was surprised I found it (though things started making more sense afterward). – John O Jan 21 '15 at 04:57
  • Python 2 is OK, it's what I use daily at work, though Py 3 is better. But old-style classes are just broken: if you can't fix that, there probably is no remedy. – Alex Martelli Jan 21 '15 at 05:01