# stuck at parsing xml from URL

**URL:** <https://forums.plex.tv/t/stuck-at-parsing-xml-from-url/31147>\
**Category:** Dev/API Corner\
**Tags:** scanner-agent-dev\
**Created:** [March 21, 2013, 6:49pm UTC](https://forums.plex.tv/t/stuck-at-parsing-xml-from-url/31147 "2013-03-21T18:49:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fribbtastic](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/fribbtastic/32/5639_2.png) [@Fribbtastic](https://forums.plex.tv/u/Fribbtastic)\
**Post date:** [March 21, 2013, 6:49pm UTC](https://forums.plex.tv/t/stuck-at-parsing-xml-from-url/31147/1 "2013-03-21T18:49:58Z")

</div>

Hello everyone,

&nbsp;

I'm new to python programming and I use plex for about 2-3 weeks now because it gave me almost every feature which I needed. So I thought while reading the plugin walkthrough how hard could it be to write my own metadata Agent so I gave it a shot. Now I'm stuck and I don't know how to fix my problem.

&nbsp;

What do I try to do exactly? Like I said, I try to write a metadata Agent for the Anime Database myanimelist.net because all my anime are organized with myanimelist in mind so why not use alle the data from myanimelist.net?! Since myanimelist provide a REST Interface with HTTP Authentication.

&nbsp;

First of some code:

```
import sys
import os
import urllib2
import base64
from xml.dom import minidom

USERNAME = Prefs[“username”]  
PASSWORD = Prefs[“password”]  
BASE\_URL = “[http://myanimelist.net/api/anime/search.xml?q=](http://myanimelist.net/api/anime/search.xml?q=)”

def Start():  
Log(“Starting MALAgent”)

class MALAgentTV(Agent.TV\_Shows):

name = “[MyAnimeList.net](http://MyAnimeList.net)”  
languages = [Locale.Language.English]  
primary\_provider = True

def search(self, results, media, lang):

```
Log("Search for anime: " + media.show)

malURL = BASE_URL + media.show
Log(malURL)
malRequest = urllib2.Request(malURL)
base64string = base64.encodestring('%s:%s' % (USERNAME, PASSWORD)).replace('

```

', ‘’)  
malRequest.add\_header(“Authorization”, “Basic %s” % base64string)  
malData = urllib2.urlopen(malRequest)

```
xmldoc = minidom.parse(malData)

return

```

def update(self, metadata, media, lang):  
return
```

the problem is that with some requests I'll get an error

> ExpatError: undefined entity: line 14, column 169

&nbsp;

which is xmldoc = minidom.parse(malData)

&nbsp;

the funny thing about this error is that it doesn't get it on every search

&nbsp;

after googling, mailinglists, forum posts and other sources it could be that the XML response is incorrect (some say because of the doctype)

&nbsp;

here is a response if i search for bleach

```
<?xml version="1.0" encoding="utf-8"?>

  
    269
    Bleach
    Bleach
    
    366
    8.01
    TV
    Finished Airing
    2004-10-05
    2012-03-27
    15-year-old Kurosaki Ichigo is not your everyday high school student. He has from as far he can remember always had the ability to see ghosts and spirits. A fateful day arrives as Ichigo encounters the shinigami Kuchiki Rukia, who saves him and his family from a Hollow at the cost of injuring herself. During this encounter, with Rukia unable to defeat the hollow she transfers her shinigami powers into Ichigo. In the aftermath, unable to continue with her job, Rukia allows Ichigo to take on the role of a shinigami in her place as they together defeat the Hollows plaguing Ichigo's town. 
    http://cdn.myanimelist.net/images/anime/3/20349.jpg
```

But actually I have no Idea what I need to do to fix that. I tried Minidom, ElementTree nothing seems to work.

&nbsp;

So if anyone could help me with this I would be really grateful

---

<div class="post-metadata">

**Author:** ![sander1](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@sander1](https://forums.plex.tv/u/sander1)\
**Post date:** [March 21, 2013, 8:07pm UTC](https://forums.plex.tv/t/stuck-at-parsing-xml-from-url/31147/2 "2013-03-21T20:07:56Z")

</div>

Hi!

You can use build-in framework functions for almost everything you need:

```
USERNAME = Prefs["username"]
PASSWORD = Prefs["password"]
BASE_URL = "http://myanimelist.net/api/anime/search.xml?q="

def Start():  
Log(“Starting MALAgent”)

class MALAgentTV(Agent.TV\_Shows):

name = “[MyAnimeList.net](http://MyAnimeList.net)”  
languages = [Locale.Language.English]  
primary\_provider = True

def search(self, results, media, lang):

```
Log("Search for anime: " + media.show)

mal_url = BASE_URL + String.Quote(media.show, usePlus=True)
Log(mal_url)

auth = String.Base64Encode('%s:%s' % (USERNAME, PASSWORD))
headers = {'Authorization': 'Basic %s' % auth}

xml = XML.ElementFromURL(mal_url, headers=headers)

return

```

def update(self, metadata, media, lang):  
return
```

---

<div class="post-metadata">

**Author:** ![Fribbtastic](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/fribbtastic/32/5639_2.png) [@Fribbtastic](https://forums.plex.tv/u/Fribbtastic)\
**Post date:** [March 23, 2013, 4:34pm UTC](https://forums.plex.tv/t/stuck-at-parsing-xml-from-url/31147/3 "2013-03-23T16:34:07Z")

</div>

Many thanks sander1 this helped me a lot to finish the agent.

---

<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:04pm UTC](https://forums.plex.tv/t/stuck-at-parsing-xml-from-url/31147/4 "2019-12-20T23:04:50Z")

</div>

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