# Unauthorized getting local media details

**URL:** <https://forums.plex.tv/t/unauthorized-getting-local-media-details/198496>\
**Category:** Dev/API Corner\
**Tags:** scanner-agent-dev\
**Created:** [July 9, 2017, 9:57am UTC](https://forums.plex.tv/t/unauthorized-getting-local-media-details/198496 "2017-07-09T09:57:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![psycik](https://avatars.discourse-cdn.com/v4/letter/p/b77776/32.png) [@psycik](https://forums.plex.tv/u/psycik)\
**Post date:** [July 9, 2017, 9:57am UTC](https://forums.plex.tv/t/unauthorized-getting-local-media-details/198496/1 "2017-07-09T09:57:30Z")

</div>

I have a metadata agent that’s based on the NFO one as it reads an XML file generated by a PVR application.

I’ve been trying to diagnose a issue with it where it’s not been firing. Now it seems to be but there’s a call to get the media tree item from plex, so that it can be updated. But I seem to be getting a unauthorised.

```
2017-07-09 21:49:59,540 (1cd4) : DEBUG (networking:166) - Requesting 'http://localhost:32400/library/metadata/184889/tree'
2017-07-09 21:50:00,546 (1cd4) : ERROR (networking:219) - Error opening URL 'http://localhost:32400/library/metadata/184889/tree'
2017-07-09 21:50:00,548 (1cd4) : CRITICAL (core:574) - Exception in the search function of agent named 'NPVR TV .xml Importer', called with keyword arguments {'openSubtitlesHash': '276ccc72bac9e1f5', 'episode': '0708', 'name': '0708', 'episodic': '1', 'show': 'Britains Got Talent', 'released_at': '2017-07-08', 'season': '2017', 'filename': 'P%3A%5CServerFolders%5CRecordings%5CBritains%20Got%20Talent%5CBritains%20Got%20Talent_20170708_19002000%2Ets', 'plexHash': '9d59d89b7a9813932d80a195a1a759f1febac1a6', 'duration': '5697838', 'id': '184889'} (most recent call last):
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-313f93718\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\api\agentkit.py", line 1007, in _search
    agent.search(*f_args, **f_kwargs)
  File "C:\Plex\Plex Media Server\Plug-ins\NPVRxmlTV.bundle\Contents\Code\ __init__.py", line 38, in search
    Log(XML.ElementFromURL(pageUrl).xpath('//MediaContainer/MetadataItem/MetadataItem/MetadataItem/MetadataItem'))
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-313f93718\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\api\parsekit.py", line 344, in ElementFromURL
    method=method,
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-313f93718\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\api

```

etworkkit.py", line 67, in \_http\_request  
req = self.\_core.networking.http\_request(url, \*args, \*\*kwargs)  
File “C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-313f93718\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\components  
etworking.py”, line 370, in http\_request  
return HTTPRequest(self.\_core, url, data, h, url\_cache, encoding, errors, timeout, immediate, sleep, opener, follow\_redirects, method)  
File “C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-313f93718\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\components  
etworking.py”, line 141, in **init**  
self.load()  
File “C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-313f93718\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\components  
etworking.py”, line 181, in load  
f = self.\_opener.open(req, timeout=self.\_timeout)  
File “C:\Program Files (x86)\Plex\Plex Media Server\python27.zip\urllib2.py”, line 435, in open  
response = meth(req, response)  
File “C:\Program Files (x86)\Plex\Plex Media Server\python27.zip\urllib2.py”, line 548, in http\_response  
‘http’, request, response, code, msg, hdrs)  
File “C:\Program Files (x86)\Plex\Plex Media Server\python27.zip\urllib2.py”, line 473, in error  
return self.\_call\_chain(\*args)  
File “C:\Program Files (x86)\Plex\Plex Media Server\python27.zip\urllib2.py”, line 407, in \_call\_chain  
result = func(\*args)  
File “C:\Program Files (x86)\Plex\Plex Media Server\python27.zip\urllib2.py”, line 556, in http\_error\_default  
raise HTTPError(req.get\_full\_url(), code, msg, hdrs, fp)  
HTTPError: HTTP Error 401: Unauthorized

```
2017-07-09 21:50:00,548 (1cd4) : DEBUG (runtime:88) - Sending packed state data (107 bytes)

```

I can confirm that trying to access [http://localhost:32400/library/metadata/184889/tree](http://localhost:32400/library/metadata/184889/tree) from the local machine does get me an unauthorised until I add ?X-plex-token=plex token here, then I get details.

How is a metadata agent supposed to do this?

---

<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:** [January 8, 2020, 8:04pm UTC](https://forums.plex.tv/t/unauthorized-getting-local-media-details/198496/2 "2020-01-08T20:04:31Z")

</div>


