prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  plexupdate plugin crashed
  Every time after import plexupdate plugin crashed with this error:
  
  ```
  Traceback (most recent call last):
    File "/usr/local/bin/beet", line 9, in <module>
      load_entry_point('beets==1.3.15', 'console_scripts', 'beet')()
    File "/usr/local/lib/python2.7/dist-packages/beets/ui/__init__.py", line 1163, in main
      _raw_main(args)
    File "/usr/local/lib/python2.7/dist-packages/beets/ui/__init__.py", line 1155, in _raw_main
      plugins.send('cli_exit', lib=lib)
    File "/usr/local/lib/python2.7/dist-packages/beets/plugins.py", line 458, in send
      result = handler(**arguments)
    File "/usr/local/lib/python2.7/dist-packages/beets/plugins.py", line 123, in wrapper
      return func(*args, **kwargs)
    File "/usr/local/lib/python2.7/dist-packages/beetsplug/plexupdate.py", line 87, in update
      config['plex']['library_name'].get())
    File "/usr/local/lib/python2.7/dist-packages/beetsplug/plexupdate.py", line 41, in update_plex
      section_key = get_music_section(host, port, token, library_name)
    File "/usr/local/lib/python2.7/dist-packages/beetsplug/plexupdate.py", line 31, in get_music_section
      tree = ET.fromstring(r.raw)
    File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1300, in XML
      parser.feed(text)
    File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1640, in feed
      self._parser.Parse(data, 0)
  TypeError: must be string or read-only buffer, not HTTPResponse
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `beetsplug/plexupdate.py`
  Content:
  ```
  1 """Updates an Plex library whenever the beets library is changed.
  2 
  3 Plex Home users enter the Plex Token to enable updating.
  4 Put something like the following in your config.yaml to configure:
  5     plex:
  6         host: localhost
  7         port: 32400
  8         token: token
  9 """
  10 from __future__ import (division, absolute_import, print_function,
  11                         unicode_literals)
  12 
  13 import requests
  14 from urlparse import urljoin
  15 from urllib import urlencode
  16 import xml.etree.ElementTree as ET
  17 from beets import config
  18 from beets.plugins import BeetsPlugin
  19 
  20 
  21 def get_music_section(host, port, token, library_name):
  22     """Getting the section key for the music library in Plex.
  23     """
  24     api_endpoint = append_token('library/sections', token)
  25     url = urljoin('http://{0}:{1}'.format(host, port), api_endpoint)
  26 
  27     # Sends request.
  28     r = requests.get(url)
  29 
  30     # Parse xml tree and extract music section key.
  31     tree = ET.fromstring(r.text)
  32     for child in tree.findall('Directory'):
  33         if child.get('title') == library_name:
  34             return child.get('key')
  35 
  36 
  37 def update_plex(host, port, token, library_name):
  38     """Sends request to the Plex api to start a library refresh.
  39     """
  40     # Getting section key and build url.
  41     section_key = get_music_section(host, port, token, library_name)
  42     api_endpoint = 'library/sections/{0}/refresh'.format(section_key)
  43     api_endpoint = append_token(api_endpoint, token)
  44     url = urljoin('http://{0}:{1}'.format(host, port), api_endpoint)
  45 
  46     # Sends request and returns requests object.
  47     r = requests.get(url)
  48     return r
  49 
  50 
  51 def append_token(url, token):
  52     """Appends the Plex Home token to the api call if required.
  53     """
  54     if token:
  55         url += '?' + urlencode({'X-Plex-Token': token})
  56     return url
  57 
  58 
  59 class PlexUpdate(BeetsPlugin):
  60     def __init__(self):
  61         super(PlexUpdate, self).__init__()
  62 
  63         # Adding defaults.
  64         config['plex'].add({
  65             u'host': u'localhost',
  66             u'port': 32400,
  67             u'token': u'',
  68             u'library_name': u'Music'})
  69 
  70         self.register_listener('database_change', self.listen_for_db_change)
  71 
  72     def listen_for_db_change(self, lib, model):
  73         """Listens for beets db change and register the update for the end"""
  74         self.register_listener('cli_exit', self.update)
  75 
  76     def update(self, lib):
  77         """When the client exists try to send refresh request to Plex server.
  78         """
  79         self._log.info('Updating Plex library...')
  80 
  81         # Try to send update request.
  82         try:
  83             update_plex(
  84                 config['plex']['host'].get(),
  85                 config['plex']['port'].get(),
  86                 config['plex']['token'].get(),
  87                 config['plex']['library_name'].get())
  88             self._log.info('... started.')
  89 
  90         except requests.exceptions.RequestException:
  91             self._log.warning('Update failed.')
  92
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/beetsplug/plexupdate.py b/beetsplug/plexupdate.py
  --- a/beetsplug/plexupdate.py
  +++ b/beetsplug/plexupdate.py
  @@ -28,7 +28,7 @@
       r = requests.get(url)
   
       # Parse xml tree and extract music section key.
  -    tree = ET.fromstring(r.text)
  +    tree = ET.fromstring(r.content)
       for child in tree.findall('Directory'):
           if child.get('title') == library_name:
               return child.get('key')
  
verification_info: {"golden_diff": "diff --git a/beetsplug/plexupdate.py b/beetsplug/plexupdate.py\n--- a/beetsplug/plexupdate.py\n+++ b/beetsplug/plexupdate.py\n@@ -28,7 +28,7 @@\n     r = requests.get(url)\n \n     # Parse xml tree and extract music section key.\n-    tree = ET.fromstring(r.text)\n+    tree = ET.fromstring(r.content)\n     for child in tree.findall('Directory'):\n         if child.get('title') == library_name:\n             return child.get('key')\n", "issue": "plexupdate plugin crashed\nEvery time after import plexupdate plugin crashed with this error:\n\n```\nTraceback (most recent call last):\n  File \"/usr/local/bin/beet\", line 9, in <module>\n    load_entry_point('beets==1.3.15', 'console_scripts', 'beet')()\n  File \"/usr/local/lib/python2.7/dist-packages/beets/ui/__init__.py\", line 1163, in main\n    _raw_main(args)\n  File \"/usr/local/lib/python2.7/dist-packages/beets/ui/__init__.py\", line 1155, in _raw_main\n    plugins.send('cli_exit', lib=lib)\n  File \"/usr/local/lib/python2.7/dist-packages/beets/plugins.py\", line 458, in send\n    result = handler(**arguments)\n  File \"/usr/local/lib/python2.7/dist-packages/beets/plugins.py\", line 123, in wrapper\n    return func(*args, **kwargs)\n  File \"/usr/local/lib/python2.7/dist-packages/beetsplug/plexupdate.py\", line 87, in update\n    config['plex']['library_name'].get())\n  File \"/usr/local/lib/python2.7/dist-packages/beetsplug/plexupdate.py\", line 41, in update_plex\n    section_key = get_music_section(host, port, token, library_name)\n  File \"/usr/local/lib/python2.7/dist-packages/beetsplug/plexupdate.py\", line 31, in get_music_section\n    tree = ET.fromstring(r.raw)\n  File \"/usr/lib/python2.7/xml/etree/ElementTree.py\", line 1300, in XML\n    parser.feed(text)\n  File \"/usr/lib/python2.7/xml/etree/ElementTree.py\", line 1640, in feed\n    self._parser.Parse(data, 0)\nTypeError: must be string or read-only buffer, not HTTPResponse\n```\n\n", "before_files": [{"content": "\"\"\"Updates an Plex library whenever the beets library is changed.\n\nPlex Home users enter the Plex Token to enable updating.\nPut something like the following in your config.yaml to configure:\n    plex:\n        host: localhost\n        port: 32400\n        token: token\n\"\"\"\nfrom __future__ import (division, absolute_import, print_function,\n                        unicode_literals)\n\nimport requests\nfrom urlparse import urljoin\nfrom urllib import urlencode\nimport xml.etree.ElementTree as ET\nfrom beets import config\nfrom beets.plugins import BeetsPlugin\n\n\ndef get_music_section(host, port, token, library_name):\n    \"\"\"Getting the section key for the music library in Plex.\n    \"\"\"\n    api_endpoint = append_token('library/sections', token)\n    url = urljoin('http://{0}:{1}'.format(host, port), api_endpoint)\n\n    # Sends request.\n    r = requests.get(url)\n\n    # Parse xml tree and extract music section key.\n    tree = ET.fromstring(r.text)\n    for child in tree.findall('Directory'):\n        if child.get('title') == library_name:\n            return child.get('key')\n\n\ndef update_plex(host, port, token, library_name):\n    \"\"\"Sends request to the Plex api to start a library refresh.\n    \"\"\"\n    # Getting section key and build url.\n    section_key = get_music_section(host, port, token, library_name)\n    api_endpoint = 'library/sections/{0}/refresh'.format(section_key)\n    api_endpoint = append_token(api_endpoint, token)\n    url = urljoin('http://{0}:{1}'.format(host, port), api_endpoint)\n\n    # Sends request and returns requests object.\n    r = requests.get(url)\n    return r\n\n\ndef append_token(url, token):\n    \"\"\"Appends the Plex Home token to the api call if required.\n    \"\"\"\n    if token:\n        url += '?' + urlencode({'X-Plex-Token': token})\n    return url\n\n\nclass PlexUpdate(BeetsPlugin):\n    def __init__(self):\n        super(PlexUpdate, self).__init__()\n\n        # Adding defaults.\n        config['plex'].add({\n            u'host': u'localhost',\n            u'port': 32400,\n            u'token': u'',\n            u'library_name': u'Music'})\n\n        self.register_listener('database_change', self.listen_for_db_change)\n\n    def listen_for_db_change(self, lib, model):\n        \"\"\"Listens for beets db change and register the update for the end\"\"\"\n        self.register_listener('cli_exit', self.update)\n\n    def update(self, lib):\n        \"\"\"When the client exists try to send refresh request to Plex server.\n        \"\"\"\n        self._log.info('Updating Plex library...')\n\n        # Try to send update request.\n        try:\n            update_plex(\n                config['plex']['host'].get(),\n                config['plex']['port'].get(),\n                config['plex']['token'].get(),\n                config['plex']['library_name'].get())\n            self._log.info('... started.')\n\n        except requests.exceptions.RequestException:\n            self._log.warning('Update failed.')\n", "path": "beetsplug/plexupdate.py"}], "after_files": [{"content": "\"\"\"Updates an Plex library whenever the beets library is changed.\n\nPlex Home users enter the Plex Token to enable updating.\nPut something like the following in your config.yaml to configure:\n    plex:\n        host: localhost\n        port: 32400\n        token: token\n\"\"\"\nfrom __future__ import (division, absolute_import, print_function,\n                        unicode_literals)\n\nimport requests\nfrom urlparse import urljoin\nfrom urllib import urlencode\nimport xml.etree.ElementTree as ET\nfrom beets import config\nfrom beets.plugins import BeetsPlugin\n\n\ndef get_music_section(host, port, token, library_name):\n    \"\"\"Getting the section key for the music library in Plex.\n    \"\"\"\n    api_endpoint = append_token('library/sections', token)\n    url = urljoin('http://{0}:{1}'.format(host, port), api_endpoint)\n\n    # Sends request.\n    r = requests.get(url)\n\n    # Parse xml tree and extract music section key.\n    tree = ET.fromstring(r.content)\n    for child in tree.findall('Directory'):\n        if child.get('title') == library_name:\n            return child.get('key')\n\n\ndef update_plex(host, port, token, library_name):\n    \"\"\"Sends request to the Plex api to start a library refresh.\n    \"\"\"\n    # Getting section key and build url.\n    section_key = get_music_section(host, port, token, library_name)\n    api_endpoint = 'library/sections/{0}/refresh'.format(section_key)\n    api_endpoint = append_token(api_endpoint, token)\n    url = urljoin('http://{0}:{1}'.format(host, port), api_endpoint)\n\n    # Sends request and returns requests object.\n    r = requests.get(url)\n    return r\n\n\ndef append_token(url, token):\n    \"\"\"Appends the Plex Home token to the api call if required.\n    \"\"\"\n    if token:\n        url += '?' + urlencode({'X-Plex-Token': token})\n    return url\n\n\nclass PlexUpdate(BeetsPlugin):\n    def __init__(self):\n        super(PlexUpdate, self).__init__()\n\n        # Adding defaults.\n        config['plex'].add({\n            u'host': u'localhost',\n            u'port': 32400,\n            u'token': u'',\n            u'library_name': u'Music'})\n\n        self.register_listener('database_change', self.listen_for_db_change)\n\n    def listen_for_db_change(self, lib, model):\n        \"\"\"Listens for beets db change and register the update for the end\"\"\"\n        self.register_listener('cli_exit', self.update)\n\n    def update(self, lib):\n        \"\"\"When the client exists try to send refresh request to Plex server.\n        \"\"\"\n        self._log.info('Updating Plex library...')\n\n        # Try to send update request.\n        try:\n            update_plex(\n                config['plex']['host'].get(),\n                config['plex']['port'].get(),\n                config['plex']['token'].get(),\n                config['plex']['library_name'].get())\n            self._log.info('... started.')\n\n        except requests.exceptions.RequestException:\n            self._log.warning('Update failed.')\n", "path": "beetsplug/plexupdate.py"}]}