Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: ParseError: unclosed token: line 104, column 12
### INFO

**Python Version**: `2.7.6 (default, Jun 22 2015, 18:00:18) [GCC 4.8.2]`
**Operating System**: `Linux-4.2.0-42-generic-i686-with-Ubuntu-14.04-trusty`
**Locale**: `None`
**Branch**: [develop](../tree/develop)
**Commit**: PyMedusa/SickRage@c6c6e8412f45c591f4257bd4bceeca84261c2913
**Link to Log**: https://gist.github.com/390d7bed2edf3e1a87218df470c99203
### ERROR

<pre>
2016-09-10 04:37:02 ERROR    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Error while refreshing show Wayward Pines. Error: unclosed token: line 104, column 12
Traceback (most recent call last):
  File "/home/home/SickRage/<a href="../blob/c6c6e8412f45c591f4257bd4bceeca84261c2913/sickbeard/show_queue.py#L581">sickbeard/show_queue.py</a>", line 581, in run
    self.show.update_metadata()
  File "/home/home/SickRage/<a href="../blob/c6c6e8412f45c591f4257bd4bceeca84261c2913/sickbeard/tv.py#L547">sickbeard/tv.py</a>", line 547, in update_metadata
    self.__update_show_nfo()
  File "/home/home/SickRage/<a href="../blob/c6c6e8412f45c591f4257bd4bceeca84261c2913/sickbeard/tv.py#L555">sickbeard/tv.py</a>", line 555, in __update_show_nfo
    result = cur_provider.update_show_indexer_metadata(self) or result
  File "/home/home/SickRage/<a href="../blob/c6c6e8412f45c591f4257bd4bceeca84261c2913/sickbeard/metadata/generic.py#L273">sickbeard/metadata/generic.py</a>", line 273, in update_show_indexer_metadata
    showXML = etree.ElementTree(file=xmlFileObj)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 611, in __init__
    self.parse(file)
  File "<string>", line 38, in parse
ParseError: unclosed token: line 104, column 12
</pre>

---

_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators



Discussion:
No idea how to fix this


Resolving patch:
diff --git a/sickbeard/metadata/generic.py b/sickbeard/metadata/generic.py
--- a/sickbeard/metadata/generic.py
+++ b/sickbeard/metadata/generic.py
@@ -269,7 +269,7 @@ def update_show_indexer_metadata(self, show_obj):
             assert isinstance(nfo_file_path, text_type)
 
             try:
-                with io.open(nfo_file_path, 'rb') as xmlFileObj:
+                with io.open(nfo_file_path, 'rb', encoding='utf8') as xmlFileObj:
                     showXML = etree.ElementTree(file=xmlFileObj)
 
                 indexerid = showXML.find('id')
@@ -287,6 +287,9 @@ def update_show_indexer_metadata(self, show_obj):
                 helpers.chmodAsParent(nfo_file_path)
 
                 return True
+            except etree.ParseError as error:
+                logger.log('Received an invalid XML for {show}, try again later. Error: {error_msg}'.format
+                           (show=show_obj.name, error_msg=error), logger.WARNING)
             except IOError as e:
                 logger.log(
                     u"Unable to write file to " + nfo_file_path + " - are you sure the folder is writable? " + ex(e),
@@ -410,7 +413,7 @@ def write_show_file(self, show_obj):
 
             logger.log(u"Writing show nfo file to " + nfo_file_path, logger.DEBUG)
 
-            nfo_file = io.open(nfo_file_path, 'wb')
+            nfo_file = io.open(nfo_file_path, 'wb', encoding='utf8')
             data.write(nfo_file, encoding='UTF-8')
             nfo_file.close()
             helpers.chmodAsParent(nfo_file_path)
@@ -454,7 +457,7 @@ def write_ep_file(self, ep_obj):
                 helpers.chmodAsParent(nfo_file_dir)
 
             logger.log(u"Writing episode nfo file to " + nfo_file_path, logger.DEBUG)
-            nfo_file = io.open(nfo_file_path, 'wb')
+            nfo_file = io.open(nfo_file_path, 'wb', encoding='utf8')
             data.write(nfo_file, encoding='UTF-8')
             nfo_file.close()
             helpers.chmodAsParent(nfo_file_path)
@@ -702,7 +705,7 @@ def _write_image(self, image_data, image_path, obj=None):
                 ek(os.makedirs, image_dir)
                 helpers.chmodAsParent(image_dir)
 
-            outFile = io.open(image_path, 'wb')
+            outFile = io.open(image_path, 'wb', encoding='utf8')
             outFile.write(image_data)
             outFile.close()
             helpers.chmodAsParent(image_path)
@@ -908,7 +911,7 @@ def retrieveShowMetadata(self, folder):
         logger.log(u"Loading show info from metadata file in " + folder, logger.DEBUG)
 
         try:
-            with io.open(metadata_path, 'rb') as xmlFileObj:
+            with io.open(metadata_path, 'rb', encoding='utf8') as xmlFileObj:
                 showXML = etree.ElementTree(file=xmlFileObj)
 
             if showXML.findtext('title') is None or (showXML.findtext('tvdbid') is None and showXML.findtext('id') is None):


Test patch: