How to access remote server via plugin?

plugin-dev

#1

I'm working on my first plugin and have a rather basic problem that is blocking me...

My plugin will be processing a playlist that can be on a remote server, however I haven't been able to figure out how to reach the remote server. When I pull "/servers" from my "https://127.0.0.1:32400/servers/?X-Plex-Token=#####", it only shows me my local server, when I expect that it would show me all servers I have access to.

Is there a different command for accessing remote servers? Anybody know of an existing plugin I could browse through that connects to a remote server?

Thanks.


#2

Try:

plex.tv/pms/servers

/T


#3

Also note, that you NEVER EVER should add the Plex token to the URL, since it then would be logged in the channel logs!

Instead, add it as a header

Best Regards

Tommy


#4

Following up in here (but may be worth a new thread), I've been able to build the interface to select the remote server now, but when I try to do XML.ElementFromURL calls to that server (using the IP/port/token extracted from pms/servers), I get the exception "Accessing the media server's HTTP interface is not permitted." If I just paste the URL I am using into a browser, the XML does come up fine. Some of the URLs I've been trying that have been causing this are:

https://IP:PORT/playlists/
https://IP:PORT/library/sections
https://IP:PORT/playlists/###/items
https://IP:PORT/library/metadata/%s

I gather there is another library like PMS that I should be using instead?


#5

@edank I've seen this error before. Plex server normally does not allow request to itself or other Plex servers via its API for some reason.

Here are some lines from networkkit.py of Plex Framework that I believe are throwing that error:

def Request(self, url, values=None, headers={}, cacheTime=None, encoding=None, errors=None, timeout=GLOBAL_DEFAULT_TIMEOUT, immediate=False, sleep=0, data=None, follow_redirects=True, method=None): 
    ...
    if url.find(':32400/') > -1 and self._sandbox.policy.elevated_execution == False:
      raise Framework.exceptions.FrameworkException("Accessing the media server's HTTP interface is not permitted.")

I have absolutely no idea why the restriction is in place, but the code also contains a hint for the solution: you could put your channel into elevated code policy. It will grant you more power over what kind of code your channel may execute and access to more Framework functions. But I hear that it could cause your channel to be rejected from the official Plex channels repository, should you decide to publish it there.

In order to enable it, you'll need to add the following keys to the channel's Info.plist and restart Plex Server:

    <key>PlexPluginCodePolicy</key>
    <string>Elevated</string>

Or alternatively, you could just use raw Python HTTP requests using eg urllib2.urlopen and avoid changing the code policy.


#6

Thank you @czukowski , I'll give those a shot!