Problem with access to PMS with Web API from inside a Plugin

Hi,
Iam trying to get access to the local PMS with the Web API from inside a Plugin.

Heres my code:

@handler(prefix, name, icon, art) def Main(): oc = None test = 'no error' try: # request = HTTP.Request('/library/sections') # request = HTTP.Request('http://localhost:32400/library/sections') request = HTTP.Request('http://127.0.0.1:32400/library/sections') request.load() data = request.content oc = ObjectContainer(header="Empty", message=data) except: test = 'failed' oc = ObjectContainer(header="Empty", message=test) return oc

Everytime Iam running the code theres throw an exception. Iam have tried the access in two different versions. Please help me, whats the problem?

Update: I have now tried the code with another Url, such the link to the forum, and it works.

You can’t just put that into a container!

Take a peak here for listing the sections

github.com/ukdtom/plex2csv.bundle/blob/master/Contents/Code/init.py

/T

Ok, thanks.

Now a the problem are exists again or is now another. Heres the new code for testing:

@handler(prefix, name, icon, art) def Main(): oc = None test = 'no error' try: XML.ElementFromURL('http://127.0.0.1:32400/library/sections') except: test = 'failed' oc = ObjectContainer(header="Empty", message=test) return oc

Everytime Iam running the code theres throw the exception.

Did you read the PDF’s I pointed you towards?

class ObjectContainer(**kwargs) A container for other objects. ObjectContainer is the type most frequently returned to other applications. It provides clients with an ordered list of items in response to a re- quest. view_group A string specifying the name of the view group the client should use when dis- playing the container’s contents. This should be the name of a group previously registered with Plugin.AddViewGroup() (page 49). 52 Chapter 6. API ReferencePlex Plug-in Framework Documentation, Release 2.1.1 content Identifies the type of the objects inside the container. This attribute should be set to one of the container type constants identified here. ..todo:: Link to container types art A string specifying an image resource that should be used as the container’s back- ground art. title1 A string specifying the first title to display in the user interface. title2 A string specifying the second title to display in the user interface. http_cookies A string specifying any HTTP cookies that need to be passed to the server when attempting to play items from the container. user_agent A string specifying the user agent header that needs to be sent to the server when attempting to play items from the container. no_history A boolean specifying whether the container should be added to the client’s history stack. For example, if Container B in the sequence A => B => C had no_cache set to True, navigating back from C would take the user directly to A. replace_parent A boolean specifying whether the container should replace the previous container in the client’s history stack. For example, if Container C in the sequence A => B => C had replace_parent set to True, navigating back from C would take the user directly to A. no_cache A boolean indicating whether the container can be cached or not. Under normal circumstances, the client will cache a container for use when navigating back up the directory tree. If no_cache is set to True, the container will be requested again when navigating back. mixed_parents A boolean indicating that the objects in the container do not share a common parent object (for example, tracks in a playlist). header message The header and message attributes are used in conjunction. They instruct the client to isplay a message dialog on loading the container, where header is the message dialog’s title and message is the body. add(obj) Adds the object obj to the container. The container can also be populated by passing a list of objects to the constructor as the objects argument: 6.1. Standard API 53Plex Plug-in Framework Documentation, Release 2.1.1 oc = ObjectContainer( objects = [ MovieObject( title = "Movie" ), VideoClipObject( title = "Video Clip" ) ] ) len(container) Containers can be passed to the len() (http://docs.py

class DirectoryObject(**kwargs) Represents a generic container of objects. Directory objects are usually used when cre- ating a navigation hierarchy. key A string specifying the path to a container representing the directory’s content. This is usually a function callback generated using Callback() (page 48). title A string specifying the directory’s title. tagline A string specifying the directory’s tagline. summary A string specifying the directory’s summary. thumb A string specifying an image resource to use as the directory’s thumbnail. art A string specifying an image resource to use as the directory’s background art. duration An integer specifying the duration of the objects provided by the directory, in mil- liseconds.

@dane22 said:
Did you read the PDF’s I pointed you towards?

Yes, I did… and was have the second problem to do with that part you posted for me? The line
XML.ElementFromURL('http://127.0.0.1:32400/library/sections')
of my code raising the exception and is my second problem.

You are trying to show a list of sections as directory objects.
The stuff I ref. from the PDF, is the two classes involved
As such, you need something like this, and written from memory, so might not work, but I did point you to a git with working code:

oc = ObjectContainer() sections = XML.ElementFromURL('http://127.0.0.1:32400/library/sections).xpath('//Directory') for section in sections: title = section.get('title') oc.add(DirectoryObject(key=Callback(MyFunction), title='Section "' + title + '"')) return oc

/T

So, again:

oc = None test = 'no error' try: XML.ElementFromURL('http://127.0.0.1:32400/library/sections') except: test = 'failed' oc = ObjectContainer(header="Empty", message=test) return oc

In wich point do I do that what you tell?

the Line:
XML.ElementFromURL('http://127.0.0.1:32400/library/sections')
…should send and receiving an element from the link and do nothing with the content…

bis the Linke is raising an exception…

the code is only for testing.

That line is fine, something else is throwing the exception.

And you try for a start to look in the log for your plugin for the exception, that might tell you more, and codewise, try and replace your code with the one I just gave you

So, I have now analyzed the Logs (Plex Media Server.log, com.myname.plugins.pluginnname), but I have not found an exceptions or something like that. Any idea?

Huh, you are the one that said it raised an exception!

Try this:

try: Some code here except Exception, e: Log.Exception('Exception happend in mycode: ' + str(e))

/T

Thank you. Now I have the error message:

2017-01-04 21:17:58,938 (700005d91000) : CRITICAL (init:19) - Exception happend in mycode: Accessing the media server’s HTTP interface is not permitted. (most recent call last):
File “/Users/xxx/Library/Application Support/Plex Media Server/Plug-ins/Recommendationizer.bundle/Contents/Code/init.py”, line 17, in Main
XML.ElementFromURL(‘http://127.0.0.1:32400/library/sections/’)
File “/Users/xxx/Applications/Plex Media Server.app/Contents/Resources/Plug-ins-b38628e/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/api/parsekit.py”, line 326, in ElementFromURL
raise Framework.exceptions.FrameworkException(“Accessing the media server’s HTTP interface is not permitted.”)
FrameworkException: Accessing the media server’s HTTP interface is not permitted.

Do you know whats the problem is?

Still not using the code I gave you here!!!

So last time…

Try my code !!!

Diff between yours and mine is:

XML.ElementFromURL('http://127.0.0.1:32400/library/sections')

vs.

sections = XML.ElementFromURL('http://127.0.0.1:32400/library/sections).xpath('//Directory')

When said, unsure if above makes a diff, but I know for a fact, that my code does work!

/T

With the error message from the log (FrameworkException: Accessing the media server’s HTTP interface is not permitted) I have found the solution for my problem. The problem is that the plugin has not “enough” right to access the HTTP interface functions from plex api. The solution is to add these parameters to the “Info.plist” file:

key: PlexPluginCodePolicy
string: Elevated

Not so…

That key enables other stuff, but not that

Hmmm, I tried your code with the same error. With google I came to this thread: https://forums.plex.tv/discussion/77203/why-plex-disabled-accessing-media-server-using-http-interface-any-alternatives

There is an problem similar to my. With the solution in the thread the exception not longer appears.