WebexCommunity / WebexPythonSDK

Work with the Webex APIs in native Python!
https://webexcommunity.github.io/WebexPythonSDK/
MIT License
238 stars 152 forks source link

messages.list() - Avoid 404s #70

Closed fdemello closed 5 years ago

fdemello commented 5 years ago

There are some instances where getting all of the messages in a room results in a 404. This is a request to have the SDK handle this scenario.

Scenario:

msgs = sdk.messages.list()
msgs = [m for m in msgs]

Results in:

File "/python/lib/python3.7/site-packages/webexteamssdk/api/messages.py", line 134, in list
    for item in items:
  File "/python/lib/python3.7/site-packages/webexteamssdk/restsession.py", line 357, in get_items
    for json_page in pages:
  File "/python/lib/python3.7/site-packages/webexteamssdk/restsession.py", line 327, in get_pages
    response = self.request('GET', next_url, erc, **kwargs)
  File "/python/lib/python3.7/site-packages/webexteamssdk/restsession.py", line 250, in request
    check_response_code(response, erc)
  File "/python/lib/python3.7/site-packages/webexteamssdk/utils.py", line 213, in check_response_code
    raise ApiError(response)
webexteamssdk.exceptions.ApiError: Response Code [404] Not Found - The URI requested is invalid or the resource requested, such as a user, does not exist. Also returned when the requested format is not supported by therequested method.
------------------------------------Request------------------------------------
GET https://api.ciscospark.com/v1/messages?roomId=<redacted>&max=50&beforeMessage=Y2lzY2
    9zcGFyazovL3VzL01FU1NBR0UvMmVhOTVlODAtNDY0Yy0xMWU3LTgyNjctYmRlMTVmOTlmNjE5
User-Agent: python-requests/2.19.1
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Authorization: Bearer <redacted>
Content-type: application/json;charset=utf-8

-----------------------------------Response------------------------------------
404 Not Found
TrackingID: <redacted>
Cache-Control: no-cache
Content-Type: application/json
Date: Wed, 09 Jan 2019 21:39:30 GMT
Server: Redacted
l5d-success-class: 1.0
Via: 1.1 linkerd
content-encoding: gzip
content-length: 135
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload

{"message":"message not found","errors":[{"description":"message not
found"}],"trackingId":"<redacted>"}

Quoting Chris:

When paging through messages in a room, eventually one of the requests will fail (with a 404 Not Found error) - even though the message referenced in the request URL is valid and does exist.

If this is the case, it sounds like Nick Mueller’s work around is to go back to the last successful request and replay it using a different page size (max<previous) such that the offending messageId won’t be requested again (it will simply be included in a page of responses- requested with a different offset).

Workaround:

Send a new message to the room and call messages.list() again. Keep doing this until you don't hit the 404.

fdemello commented 5 years ago

I was informed by Webex Teams Support that engineering has fixed this issue.