If you have not already, we suggest setting your Plex username to something else rather than email which is displayed on your posts in forum. You can change the username at https://app.plex.tv/desktop#!/account
Welcome to our forums! Please take a few moments to read through our Community Guidelines (also conveniently linked in the header at the top of each page). There, you'll find guidelines on conduct, tips on getting the help you may be searching for, and more!

How to access remote server via plugin?

edankedank Posts: 3Members, Plex Pass Plex Pass

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.

Best Answer

Answers

  • dane22dane22 Posts: 10,339Members, Plex Pass, Plex Ninja Plex Ninja

    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

    I hate bugs - Tommy Lee Jones, MIB
    Join me in developing: epg-dk, str2utf-8, remidx, ExportTools, WebTools
    Support the Samsung Client:Donate
    Guides I use: Media Naming Guide, Local subtitles, Log-Files, QNAP FAQ, The Plex Dance

    NO Support via PM, unless called by me

  • edankedank Posts: 3Members, Plex Pass Plex Pass

    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?

  • czukowskiczukowski Posts: 141Members ✭✭✭

    @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.

  • edankedank Posts: 3Members, Plex Pass Plex Pass

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

Sign In or Register to comment.