# 401 error when accessing xml data with script via localhost

**URL:** <https://forums.plex.tv/t/401-error-when-accessing-xml-data-with-script-via-localhost/347830>\
**Category:** Dev/API Corner\
**Tags:** server-linux\
**Created:** [December 16, 2018, 7:04am UTC](https://forums.plex.tv/t/401-error-when-accessing-xml-data-with-script-via-localhost/347830 "2018-12-16T07:04:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Moe\_Fwacky](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/moe_fwacky/32/18594_2.png) [@Moe\_Fwacky](https://forums.plex.tv/u/Moe_Fwacky)\
**Post date:** [December 16, 2018, 7:04am UTC](https://forums.plex.tv/t/401-error-when-accessing-xml-data-with-script-via-localhost/347830/1 "2018-12-16T07:04:15Z")

</div>

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](https://github.com/MoeFwacky/Plex-Now-Playing-Display) 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.

---

<div class="post-metadata">

**Author:** ![ChuckPa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/chuckpa/32/79710_2.png) [@ChuckPa](https://forums.plex.tv/u/ChuckPa)\
**Post date:** [December 16, 2018, 7:28am UTC](https://forums.plex.tv/t/401-error-when-accessing-xml-data-with-script-via-localhost/347830/2 "2018-12-16T07:28:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Moe\_Fwacky](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/moe_fwacky/32/18594_2.png) [@Moe\_Fwacky](https://forums.plex.tv/u/Moe_Fwacky)\
**Post date:** [December 16, 2018, 9:24am UTC](https://forums.plex.tv/t/401-error-when-accessing-xml-data-with-script-via-localhost/347830/3 "2018-12-16T09:24:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [March 16, 2019, 9:28am UTC](https://forums.plex.tv/t/401-error-when-accessing-xml-data-with-script-via-localhost/347830/4 "2019-03-16T09:28:08Z")

</div>

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