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

HTTP 400 on msg.read() (sometimes) #207

Open
truenicoco opened this issue Jul 15, 2022 · 2 comments
Open

HTTP 400 on msg.read() (sometimes) #207

truenicoco opened this issue Jul 15, 2022 · 2 comments

Comments

@truenicoco
Copy link

Marking a message as read sometimes raise a 400 response from PUT.

I did not manage to understand exactly when or why it happens, but it is not uncommon at all

Account type

Live account - app password

Conversation details

1 on 1

Steps to reproduce

from threading import Thread

import skpy

def skype_blocking():
    while True:
        for event in sk.getEvents():
            print(event)
            if isinstance(event, skpy.SkypeNewMessageEvent):
                if event.msg.userId != sk.userId:
                    print(event.msg)
                    print("Attempting to mark it as read")
                    event.msg.read()

sk = skpy.Skype(user, pass)

Thread(target=skype_blocking).start()

input()  # just to keep the thing going
# then wait for a few messages, since it does not happen all the time...

Result or traceback

=> [15/07 22:20:18] 200
{'Cache-Control': 'no-store, must-revalidate, no-cache',
 'Content-Encoding': 'gzip',
 'Content-Length': '461',
 'Content-Type': 'application/json; charset=utf-8',
 'ContextId': 'tcid=6903253961969671623,server=SN3PEPF00009CED',
 'Date': 'Fri, 15 Jul 2022 20:20:17 GMT',
 'Pragma': 'no-cache',
 'X-Content-Type-Options': 'nosniff'}
{'eventMessages': [{'id': 1024,
                    'resource': {'ackrequired': 'https://azscus1-client-s.gateway.messenger.live.com/v1/users/ME/conversations/ALL/messages/1657916418393/ack',
                                 'clientmessageid': '15356246672076019567',
                                 'composetime': '2022-07-15T20:20:18.321Z',
                                 'content': 'comprends pas',
                                 'contenttype': 'text',
                                 'conversationLink': 'https://azscus1-client-s.gateway.messenger.live.com/v1/users/ME/conversations/8:OTHERPARTYSKYPEID',
                                 'counterpartymessageid': '1657916418393',
                                 'from': 'https://azscus1-client-s.gateway.messenger.live.com/v1/users/ME/contacts/8:OTHERPARTYSKYPEID',
                                 'id': '1657916418393',
                                 'imdisplayname': 'Nico Prout',
                                 'isactive': True,
                                 'messagetype': 'RichText',
                                 'mlsEpoch': '0',
                                 'originalarrivaltime': '2022-07-15T20:20:18.321Z',
                                 'origincontextid': '0',
                                 'receiverdisplayname': 'REDACTED',
                                 'threadtopic': 'OTHERPARTYSKYPEID, '
                                                'REDACTED',
                                 'type': 'Message',
                                 'version': '1657916418393'},
                    'resourceLink': 'https://azscus1-client-s.gateway.messenger.live.com/v1/users/ME/conversations/8:OTHERPARTYSKYPEID/messages/1657916418393',
                    'resourceType': 'NewMessage',
                    'time': '2022-07-15T20:20:18Z',
                    'type': 'EventMessage'}]}
[SkypeNewMessageEvent]
Id: 1024
Type: NewMessage
Time: 2022-07-15 20:20:18
MsgId: 1657916418393
[SkypeTextMsg]
Id: 1657916418393
Type: RichText
Time: 2022-07-15 20:20:18.321000
ClientId: 15356246672076019567
UserId: OTHERPARTYSKYPEID
ChatId: 8:OTHERPARTYSKYPEID
Content: comprends pas
Attempting to mark it as read
<= [15/07 22:20:18] PUT https://azscus1-client-s.gateway.messenger.live.com/v1/users/ME/conversations/8:OTHERPARTYSKYPEID/properties
{'json': {'consumptionhorizon': '15356246672076019567;1657916418490;15356246672076019567'},
 'params': {'name': 'consumptionhorizon'}}
=> [15/07 22:20:18] 400
{'Cache-Control': 'no-store, must-revalidate, no-cache',
 'Content-Length': '70',
 'Content-Type': 'application/json; charset=utf-8',
 'ContextId': 'tcid=2776881302533368130,server=SN3PEPF00009CED',
 'Date': 'Fri, 15 Jul 2022 20:20:18 GMT',
 'Pragma': 'no-cache',
 'StatusText': 'Update Conversation has invalid property'}
{'errorCode': 202, 'message': 'Update Conversation has invalid property'}
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/tmp/sktest.py", line 13, in skype_blocking
    event.msg.read()
  File "/home/nicoco/.cache/pypoetry/virtualenvs/slidge-AjQFdees-py3.9/lib/python3.9/site-packages/skpy/msg.py", line 278, in read
    self.chat.setConsumption("{0};{1};{0}".format(self.clientId, int(time.time() * 1000)))
  File "/home/nicoco/.cache/pypoetry/virtualenvs/slidge-AjQFdees-py3.9/lib/python3.9/site-packages/skpy/chat.py", line 266, in setConsumption
    self.skype.conn("PUT", "{0}/users/ME/conversations/{1}/properties".format(self.skype.conn.msgsHost, self.id),
  File "/home/nicoco/.cache/pypoetry/virtualenvs/slidge-AjQFdees-py3.9/lib/python3.9/site-packages/skpy/conn.py", line 237, in __call__
    raise SkypeApiException("{0} response from {1} {2}".format(resp.status_code, method, url), resp)
skpy.core.SkypeApiException: ('400 response from PUT https://azscus1-client-s.gateway.messenger.live.com/v1/users/ME/conversations/8:OTHERPARTYSKYPEID/properties', <Response [400]>)
@truenicoco truenicoco changed the title HTTP 400 when on msg.read() (sometimes) HTTP 400 on msg.read() (sometimes) Jul 15, 2022
@Terrance
Copy link
Owner

Can you find the corresponding call in your browser's network request history when you read a message in Skype for Web? If it's inconsistent then that horizon value likely isn't being generated correctly.

@truenicoco
Copy link
Author

Sorry for not getting back to this earlier. I would be happy to help debug this, but it's a bit tricky because after using the skpy client, it seems that messages sent to me are automatically, instantly marked as read as soon as they are sent. So the horizon value thing sounds like a plausible theory to me, ie, maybe skpy sends "I have read up to sometime_in_the_future" at some point; the fact that it does not happen all the time is weird though.

Feel free to add me on skype (same handle as here) if you want to test it out in case we manage to be available at the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants