Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] "Object of type coroutine is not JSON serializable" in media_seen(), easy fix #116

Open
luca-arch opened this issue Oct 21, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@luca-arch
Copy link

Try HikerAPI SaaS with a free trial https://hikerapi.com/p/KhMxYMSn

Describe the bug

ERROR [2024-10-21 05:54:50] instagram_api: Object of type coroutine is not JSON serializable

async def media_seen(self, media_ids: List[str], skipped_media_ids: List[str] = []):

This happens because gen() is not awaited:

"reels": gen(media_ids),
"live_vods": {},
"reel_media_skipped": gen(skipped_media_ids),

To Reproduce

await client.media_seen([ "01234", "56789", ])

Traceback

Traceback (most recent call last):
  File "/mnt/modules/accountman/client.py", line 96, in put_story_seen
    await self.cl.story_seen([media_id])
  File "/usr/local/lib/python3.12/site-packages/aiograpi/mixins/story.py", line 239, in story_seen
    return await self.media_seen(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiograpi/mixins/media.py", line 960, in media_seen
    result = await self.private_request(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiograpi/mixins/private.py", line 619, in private_request
    raise e
  File "/usr/local/lib/python3.12/site-packages/aiograpi/mixins/private.py", line 611, in private_request
    await self._send_private_request(endpoint, **kwargs)
  File "/usr/local/lib/python3.12/site-packages/aiograpi/mixins/private.py", line 336, in _send_private_request
    data = generate_signature(dumps(data))
                              ^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiograpi/utils.py", line 95, in dumps
    return InstagrapiJSONEncoder(separators=(",", ":")).encode(data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiograpi/utils.py", line 53, in default
    return json.JSONEncoder.default(self, obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type coroutine is not JSON serializable

Expected behavior
The coroutine should be awaited.

Screenshots

Desktop (please complete the following information):

  • OS: any
  • Python version 3.12-5
  • aiograpi version [0.0.3]

Additional context
The fix should be fairly easy to apply

        data = {
            "container_module": "feed_timeline",
            "live_vods_skipped": {},
            "nuxes_skipped": {},
            "nuxes": {},
-            "reels": gen(media_ids),
+            "reels": await gen(media_ids), 
            "live_vods": {},
-            "reel_media_skipped": gen(skipped_media_ids),
+            "reel_media_skipped": await gen(skipped_media_ids),
        }
@luca-arch luca-arch added the bug Something isn't working label Oct 21, 2024
luca-arch added a commit to luca-arch/aiograpi that referenced this issue Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant