401 error when accessing xml data with script via localhost

Attempting to pull session stats data from the xml at :32400/status/sessions?X-Plex-Token= gives a 401 unauthorized error when running a script from the same machine.

I’ve tried with file_get_contents in this php script and also tried using curl from the command line. Curl gives the 401 error using both localhost and 127.0.0.1, but properly reads using the device IP address, but any attempts at alternatives to file_get_contents in the script so far haven’t worked.

My understanding is that there is some security built into plex that prevents access to scripts through localhost, but I’m no network engineer so I’m not sure the best way to work around this for this particular script.

X-Plex-Token is required, even on the loopback adapter.
Since the general form you showed includes it, the request itself when expanded might be looking for something its not accessing correctly.

Are you using the correct Plex Account & Token?

Yeah the account and token are correct. I’ve checked a few times.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.