andy29485 / embypy

python wrapper for the emby rest api
GNU Lesser General Public License v3.0
16 stars 7 forks source link

ContentTypeError when calling update_sync() on EmbyObject #5

Closed nterupt closed 5 years ago

nterupt commented 5 years ago

I am trying to retrive the overview for an episode item.

I have executed the following commands.

import embypy
server = embypy.Emby('https;//XYZ.COM:123',api_key='deadbeef',device_id='python3')
result = server.search_sync('exact episode title')
episode = result[0]
print(episode.name)

[GET 'exact episode title']

print(episode.overview) [GET A BLANK OUTPUT]

Trying to figure out if the overview wasn't getting queried properly I ran:

episode.update_sync()

and got the following traceback

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/xyz/.local/lib/python3.5/site-packages/embypy/objects/object.py", line 244, in update_sync
    return self.connector.sync_run(self.update())
  File "/home/xyz/.local/lib/python3.5/site-packages/embypy/utils/connector.py", line 161, in sync_run
    return asyncio.get_event_loop().run_until_complete(f)
  File "/usr/lib/python3.5/asyncio/base_events.py", line 466, in run_until_complete
    return future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/home/xyz/.local/lib/python3.5/site-packages/embypy/objects/object.py", line 268, in update
    Fields='Path,Overview,'+fields
  File "/home/xyz/.local/lib/python3.5/site-packages/embypy/utils/connector.py", line 400, in getJson
    return await (await self.get(path, **query)).json()
  File "/home/xyz/.local/lib/python3.5/site-packages/aiohttp/client_reqrep.py", line 1027, in json
    headers=self.headers)
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html'

Is there ultimately an issue with how I am using the API?

andy29485 commented 5 years ago

Ah, sorry. It also needs a userid. the line should look something like this

server = embypy.Emby('https;//XYZ.COM:123',api_key='deadbeef',device_id='python3', userid='some hex string')

I should change the main object creation thing to give errors. The 2 (minimal, you can specify more args) modes of creating it should be:

embypy.Emby([url=]url, userid=..., api_key=...)

or

embypy.Emby([url=]url, username='...', password='...')

The problem is that userid is not needed for most of the requests, but it is needed for some, login only requires an api key (in this auth mode), but api keys are not connected to a specific account (so an api key can be used to login as any user... I think). I'll get that fix soon-ish.

edit: (side note:) device id is not really a needed parameter

andy29485 commented 5 years ago

After a further check, it seems that I had the check for device_id and it would throw an error if you didn't give that... but then a few lines later it would insert a default if not given... my bad (fixed to check for userid now).