pyinat/pyinaturalist

Async loop gets included in request params

JWCook opened this issue · 2 comments

A workaround is to add loop to common params to exclude. It shouldn't be getting mixed with request params to begin with, though.

Example traceback from Ben:

[2023-03-03 10:10:23] [ERROR] red: Exception in command 'event join'
Traceback (most recent call last):
  File "/home/synrg/.cache/pypoetry/virtualenvs/dronefly-xT1cyIDA-py3.9/lib/python3.9/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/synrg/work/dronefly/inatcog/commands/event.py", line 109, in event_join
    await self._event_action(ctx, "join", abbrev, user)
  File "/home/synrg/work/dronefly/inatcog/commands/event.py", line 74, in _event_action
    response = await self.api.update_project_users(
  File "/home/synrg/work/dronefly/inatcog/api.py", line 396, in update_project_users
    response = inat.projects.add_users(project_id, user_ids, access_token=token)
  File "/home/synrg/.cache/pypoetry/virtualenvs/dronefly-xT1cyIDA-py3.9/lib/python3.9/site-packages/forge/_revision.py", line 328, in inner
    return callable(*mapped.args, **mapped.kwargs)
  File "/home/synrg/.cache/pypoetry/virtualenvs/dronefly-xT1cyIDA-py3.9/lib/python3.9/site-packages/pyinaturalist/controllers/project_controller.py", line 63, in add_users
    response = self.client.request(add_project_users, project_id, user_ids, **params)
  File "/home/synrg/.cache/pypoetry/virtualenvs/dronefly-xT1cyIDA-py3.9/lib/python3.9/site-packages/pyinaturalist/client.py", line 183, in request
    return request_function(*args, **kwargs)
  File "/home/synrg/.cache/pypoetry/virtualenvs/dronefly-xT1cyIDA-py3.9/lib/python3.9/site-packages/pyinaturalist/v1/projects.py", line 185, in add_project_users
    return update_project(project_id, project_observation_rules_attributes=new_rules, **params)
  File "/home/synrg/.cache/pypoetry/virtualenvs/dronefly-xT1cyIDA-py3.9/lib/python3.9/site-packages/forge/_revision.py", line 328, in inner
    return callable(*mapped.args, **mapped.kwargs)
  File "/home/synrg/.cache/pypoetry/virtualenvs/dronefly-xT1cyIDA-py3.9/lib/python3.9/site-packages/pyinaturalist/v1/projects.py", line 298, in update_project
    response = put(
  File "/home/synrg/.cache/pypoetry/virtualenvs/dronefly-xT1cyIDA-py3.9/lib/python3.9/site-packages/pyinaturalist/session.py", line 370, in put
    return session.request('PUT', url, **kwargs)
  File "/home/synrg/.cache/pypoetry/virtualenvs/dronefly-xT1cyIDA-py3.9/lib/python3.9/site-packages/pyinaturalist/session.py", line 239, in request
    request = self.prepare_inat_request(
  File "/home/synrg/.cache/pypoetry/virtualenvs/dronefly-xT1cyIDA-py3.9/lib/python3.9/site-packages/pyinaturalist/session.py", line 196, in prepare_inat_request
    return super().prepare_request(request)
  File "/home/synrg/.cache/pypoetry/virtualenvs/dronefly-xT1cyIDA-py3.9/lib/python3.9/site-packages/requests/sessions.py", line 484, in prepare_request
    p.prepare(
  File "/home/synrg/.cache/pypoetry/virtualenvs/dronefly-xT1cyIDA-py3.9/lib/python3.9/site-packages/requests/models.py", line 371, in prepare
    self.prepare_body(data, files, json)
  File "/home/synrg/.cache/pypoetry/virtualenvs/dronefly-xT1cyIDA-py3.9/lib/python3.9/site-packages/requests/models.py", line 511, in prepare_body
    body = complexjson.dumps(json, allow_nan=False)
  File "/usr/local/lib/python3.9/json/__init__.py", line 234, in dumps
    return cls(
  File "/usr/local/lib/python3.9/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/lib/python3.9/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/local/lib/python3.9/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Loop is not JSON serializable

@synrg Is this still an issue, or did it disappear after recent changes?

synrg commented

I haven't had a recurrence. It may have been a consequence of some debug logging of my own in dronefly code. Go ahead and close it.