Why is self.plugin considered a NoneType object?

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
Septik
Posts: 39
Joined: Sun Feb 15, 2015 1:29 pm

Why is self.plugin considered a NoneType object?

Post by Septik » Mon Oct 16, 2017 5:49 am

This line:

Code: Select all

client_id = self.plugin.client_id
is giving me the following error:

Code: Select all

AttributeError: 'NoneType' object has no attribute 'client_id'
This happens when I try to call a specific method from outside it's class. I do that like so:

Code: Select all

AddToPlaylist.refreshAccessToken(AddToPlaylist(), refresh_token)
If I remove the "AddToPlaylist()" parameter I get an error saying something like "First parameter must be an instance of AddToPlaylist". I can call the same method without error from within the AddToPlaylist class, like so:

Code: Select all

self.refreshAccessToken(refresh_token)
What am I doing wrong here?

User avatar
kgschlosser
Site Admin
Posts: 5498
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Why is self.plugin considered a NoneType object?

Post by kgschlosser » Mon Oct 16, 2017 9:18 am

need to see the context the code is used in.


self.plugin is for use to access the main plugin class and there has to be a method/property/attribute in the plugin class to access. basically it has to begin with self.

example:

Code: Select all


class Plugin(eg.PluginBase):
    def __init__(self):
        self.someAttribute = 0
        self.AddAction(Action)
        
    def SomeMethod(self):
        print 'Hello World'
        
class Action(eg.ActionBase):
    def __call__(self):
        if self.plugin.someAttribute == 0:
            self.plugin.SomeMethod()
            
self.plugin does not exist in the plugin class. you would simply use self.
If you like the work I have been doing then feel free to Image

Post Reply