def query(self, key, method=None, headers=None, timeout=None, **kwargs):
url = self.url(key)<EOL>method = method or self._session.get<EOL>timeout = timeout or TIMEOUT<EOL>log.debug('<STR_LIT>', method.__name__.upper(), url)<EOL>headers = self._headers(**headers or {})<EOL>response = method(url, headers=headers, timeout=timeout, **kwargs)<EOL>if response.status_code not in (<NUM_LIT:200>, <NUM_LIT>):<EOL><INDENT>codename = codes.get(response.status_code)[<NUM_LIT:0>]<EOL>errtext = response.text.replace('<STR_LIT:\n>', '<STR_LIT:U+0020>')<EOL>log.warning('<STR_LIT>' % (response.status_code, codename, response.url, errtext))<EOL>raise BadRequest('<STR_LIT>' % (response.status_code, codename, response.url, errtext))<EOL><DEDENT>data = response.text.encode('<STR_LIT:utf8>')<EOL>return ElementTree.fromstring(data) if data.strip() else None<EOL>
Main method used to handle HTTPS requests to the Plex server. This method helps
            by encoding the response to utf-8 and parsing the returned XML into and
            ElementTree object. Returns None if no data exists in the response.