# Critical Error showing up in custom Agent

**URL:** <https://forums.plex.tv/t/critical-error-showing-up-in-custom-agent/33436>\
**Category:** Dev/API Corner\
**Tags:** scanner-agent-dev\
**Created:** [April 26, 2013, 3:41pm UTC](https://forums.plex.tv/t/critical-error-showing-up-in-custom-agent/33436 "2013-04-26T15:41:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PiX64](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@PiX64](https://forums.plex.tv/u/PiX64)\
**Post date:** [April 26, 2013, 3:41pm UTC](https://forums.plex.tv/t/critical-error-showing-up-in-custom-agent/33436/1 "2013-04-26T15:41:41Z")

</div>

Hello - I was browsing through the plugin logs for my custom Agent code and came across a critical error which Im not sure exactly what it means and how to attempt to fix it. &nbsp;It doesn't seem to be affecting the code for the most part (all metadata, posters, etc. show up) but There are a few cases where the shows don't populate full metadata from the source, when the metadata does in fact exists. &nbsp;This is the only error that seems to point to a possible culprit:

&nbsp;

Error:

&nbsp;

CRITICAL (core:561) - Exception in the search function of agent named 'SageTV BMT Agent (TV Shows)', called with keyword arguments {'openSubtitlesHash': '57fce635f544e009', 'episode': '12', 'name': 'Welcome to Alancrest', 'episodic': '1', 'show': 'Two and a Half Men', 'season': '10', 'filename': '%5C%5C192%2E168%2E1%2E110%5CConvSage%5CTwoandaHalfMen-S10E12-WelcometoAlancrest-15292365-0%2Eavi', 'plexHash': '51e4101450d59cfb53c91b757652819737bf6b2b', 'duration': '-1', 'id': '53330'} (most recent call last):

&nbsp; File "C:\Users\pix64\AppData\Local\Plex Media Server\Plug-ins\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\api\agentkit.py", line 923, in \_search

&nbsp; &nbsp; agent.search(results, media, lang)

TypeError: search() takes exactly 3 arguments (4 given)

&nbsp;

&nbsp;

Agent Search Function:

```
def search(self, results, media, lang, manual):
	#filename = media.items[0].parts[0].file.decode('utf-8')
	Log.Debug(" **** STARTTTTTTTT")
	if(not readPropertiesFromPropertiesFile()):
		Log.Debug(" **** UNABLE TO READ BMTAGENT.PROPERTIES FILE... aborting search")

```
quotedFilepathAndName = media.filename
Log.Debug(' **** media.id=%s; media.filename=%s' % (str(media.id), quotedFilepathAndName))
unquotedFilepathAndName = urllib.unquote(quotedFilepathAndName)
# Pull out just the filename to use
unquotedFilename = getFilenameOnly(unquotedFilepathAndName)
Log.Debug(' **** unquotedFilepathAndName=%s' % unquotedFilepathAndName)
Log.Debug(' **** unquotedFilename=%s' % unquotedFilename)
(filename, ext) = os.path.splitext(unquotedFilename)
Log.Debug(' **** filename = %s' % filename)
mf = getMediaFileForFilePath(filename)

if(mf): # this would only return false if there is a file on the Plex import directory but that file is not yet in Sage's DB
	airing = mf.get('Airing')
	show = airing.get('Show')
	# Check if the Sage recording is a movie or film; if it is, ignore it (workaround for user is to move movies out to a separate import directory that Plex can read an import as Movie content vs. TV Show content
	category = show.get('ShowCategoriesString')
	if(category.find("Movie")<0 and category.find("Movies")<0 and category.find("Film")<0):
		startTime = float(show.get('OriginalAiringDate') // 1000)
		airDate = date.fromtimestamp(startTime)
		mfid = str(mf.get('MediaFileID'))
		results.Append(MetadataSearchResult(id=mfid, name=media.show, score=100, lang=lang, year=airDate.year))
	else:
		Log.Debug('***Movies/Movies/Film found, ignoring and will not call update; categorylist=%s' % category)

```
```

&nbsp;

&nbsp;

Any ideas which may point me in the direction of a possible fix?

&nbsp;

---

<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:** [December 20, 2019, 11:16pm UTC](https://forums.plex.tv/t/critical-error-showing-up-in-custom-agent/33436/2 "2019-12-20T23:16:51Z")

</div>

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