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

Connection timed out #294

Open
3 tasks done
khurshid-alam opened this issue Mar 13, 2025 · 16 comments
Open
3 tasks done

Connection timed out #294

khurshid-alam opened this issue Mar 13, 2025 · 16 comments
Labels

Comments

@khurshid-alam
Copy link

khurshid-alam commented Mar 13, 2025

Before we start...

  • I've searched existing issues, but my problem hasn't been reported yet.
  • I've read the documentation (including notes on error messages and rate limiting), but my problem is something else.
  • I've tested the behaviour on Skype for Web, and it works there but not with SkPy.

Summary

Since march 10 I am getting connection timed out. It seems sk.user didn't get the token and kept requesting until hit the limit

Code sample

from skpy import Skype, SkypeChats







sk = Skype("******", "****") # connect to Skype

sk.user # you

#for contact in sk.contacts:
#    print(contact.id)

Code output

File "/Users/sunny/Documents/Desktop-Projects/Scarlet-Sparrow/Python/Skype/skype.py", line 39, in <module>
    sk = Skype("***", "***") # connect to Skype
  File "/opt/homebrew/lib/python3.13/site-packages/skpy/main.py", line 69, in __init__
    self.conn.getSkypeToken()
    ~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/opt/homebrew/lib/python3.13/site-packages/skpy/conn.py", line 197, in inner
    return method(*args, **kwargs)
  File "/opt/homebrew/lib/python3.13/site-packages/skpy/conn.py", line 438, in liveLogin
    self.getRegToken()
    ~~~~~~~~~~~~~~~~^^
  File "/opt/homebrew/lib/python3.13/site-packages/skpy/conn.py", line 520, in getRegToken
    token, expiry, msgsHost, endpoint = SkypeRegistrationTokenProvider(self).auth(self.tokens["skype"])
                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.13/site-packages/skpy/conn.py", line 952, in auth
    endpointResp = self.conn("POST", "{0}/users/ME/endpoints".format(msgsHost), codes=(200, 201, 404),
                             headers=headers, json={"endpointFeatures": "Agent"})
  File "/opt/homebrew/lib/python3.13/site-packages/skpy/conn.py", line 239, in __call__
    resp = self.sess.request(method, url, headers=headers, **kwargs)
  File "/opt/homebrew/lib/python3.13/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/opt/homebrew/lib/python3.13/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/opt/homebrew/lib/python3.13/site-packages/requests/adapters.py", line 688, in send
    raise ConnectTimeout(e, request=request)
requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='client-s.gateway.messenger.live.com', port=443): Max retries exceeded with url: /v1/users/ME/endpoints (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x1048e3750>, 'Connection to client-s.gateway.messenger.live.com timed out. (connect timeout=None)'))

Explain your code

Simple test code

SkPy version

Latest

Python version

3.10

Anything else?

No response

@Terrance Terrance marked this as a duplicate of #293 Mar 13, 2025
@Terrance
Copy link
Owner

Based on a note in #290 (reply in thread) and a quick review of Skype for Web's activity, changes seem to be:

  • messaging host is now msgapi.teams.live.com (likely as part of the incoming Teams migration)
  • endpoints are no longer configurable
  • authentication has changed (now uses an Authentication header and requires client info)

I've pushed a minimal fix to branch teams-migration, which seems to be enough to list chats and messages on my account, so please report any further problems with that fix applied.

You can install it via the repo with pip install git+https://github.com/Terrance/SkPy@teams-migration.

@khurshid-alam
Copy link
Author

I confirm with this sending chat message to a contact or a group/thread is also working.

I will report if anything happens before we migrated to teams.

Thanks.

@bellatorioxd
Copy link

bellatorioxd commented Mar 13, 2025

Thanks for the update.
However, when trying to send more than 3 messages in a row i get an error message:

raise SkypeRateLimitException("Rate limit exceeded", resp)
skpy.core.SkypeRateLimitException: ('Rate limit exceeded', <Response [429]>)

Code sample which was working fine recently:

for chat_id in chats:
    ch = sk.chats.chat(chat_id)
    ch.sendMsg("test")

@Terrance
Copy link
Owner

If they've tightened the rate limits as part of this migration then there's little we can do about it.

Do you get similarly limited using Skype for Web?

@bellatorioxd
Copy link

In Skype for Web I can send how many messages I want without any rate limit.

@Terrance
Copy link
Owner

Try again with the latest commit. If you're still being unreasonably limited, take a look at the headers and body of the failing request in SkPy (with SKPY_DEBUG_HTTP=1) vs. what Skype for Web is doing.

@bellatorioxd
Copy link

It helped to increase the number of messages to 7 before getting rate limited.
It seems like the limit is 6-7 requests per minute. That's what I can see with SKPY_DEBUG_HTTP=1 as well.
Thanks a lot for your help.

@robbely
Copy link

robbely commented Mar 14, 2025

If (part of) the fix is to change the server to a Teams one, does that mean this can be adapted for Teams in the future (eg a TmPy)?

@ilwu
Copy link

ilwu commented Mar 14, 2025

I encountered an issue during initialization.

After running:

pip install git+https://github.com/Terrance/SkPy@teams-migration

I received the following error:

File "/usr/local/lib/python3.9/site-packages/skpy/conn.py", line 267, in __call__: [SkypeApiException] 
('501 response from POST https://msgapi.teams.live.com/v1/users/ME/endpoints/SELF/subscriptions', <Response [501]>)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[20250314 05:52:15 ERROR   ] Full traceback:
  File "/app/skypebot.py", line 555, in main
    sp.loop()
  File "/usr/local/lib/python3.9/site-packages/skpy/main.py", line 213, in loop
    self.cycle()
  File "/usr/local/lib/python3.9/site-packages/skpy/main.py", line 198, in cycle
    events = self.getEvents()
  File "/usr/local/lib/python3.9/site-packages/skpy/conn.py", line 79, in wrapper
    return fn(self, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/skpy/conn.py", line 79, in wrapper
    return fn(self, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/skpy/main.py", line 111, in getEvents
    for json in self.conn.endpoints["self"].getEvents():
  File "/usr/local/lib/python3.9/site-packages/skpy/conn.py", line 1173, in getEvents
    self.subscribe()
  File "/usr/local/lib/python3.9/site-packages/skpy/conn.py", line 1136, in subscribe
    self.conn("POST", "{0}/users/ME/endpoints/{1}/subscriptions".format(self.conn.msgsHost, self.id),
  File "/usr/local/lib/python3.9/site-packages/skpy/conn.py", line 267, in __call__
    raise SkypeApiException("{0} response from {1} {2}".format(resp.status_code, method, url), resp)


Could you please help me troubleshoot this? Thank you!

@sergio-gamez
Copy link

I encountered the exact same error as described above.

Has anyone found a solution or workaround for this?

@Terrance
Copy link
Owner

From watching Skype for Web, it doesn't look like it listens for events any more?

If you receive a message while a different chat is selected, the message doesn't come through. After a while (e.g. if you leave the tab in the background and later return to it), the client refreshes the conversation list, notices the chat has been updated, then fetches its messages again to get the new one.

This probably means the long-polling call we use for listening to events doesn't exist in the Teams-backed API (this also lines up with the 501 error, which corresponds to HTTP 501 Not Implemented), so skpy.SkypeEventLoop won't work any more unless someone else can spot a suitable replacement.

You can do something similar to Skype for Web and manually poll for updates via SkypeChats.recent() (which tells you which chats to fetch messages from) and SkypeChat.getMsgs() -- both of these should return a list of their respective objects (updated chats or unseen messages) since the last call, or an empty list if nothing's changed in the meantime.

@mihalt
Copy link

mihalt commented Mar 16, 2025

@Terrance also I get skpy.core.SkypeRateLimitException: ('Rate limit exceeded', <Response [429]>) on this place

chat = SkypeChat.fromRaw(self.skype, json)

It happens when I try to do self.chats.recent(). So, it starts successfully, as I see from your SKPY_DEBUG_HTTP=1 debugging mode. But after some requests it fails with

{"errorCode":429,"message":"API calls quota exceeded!","standardizedError":{"errorCode":429,"errorSubCode":1,"errorDescription":"API calls quota exceeded!"}}{"errorCode":429,"message":"API calls quota exceeded!","standardizedError":{"errorCode":429,"errorSubCode":1,"errorDescription":"API calls quota exceeded!"}}

So, looks like that I have too much conversations to get all chats objects to a list. And I can't set limits of requests, because it is part of your lib (just after fork). Do you have any ideas of way out?

@Mizokuiam

This comment has been minimized.

@Terrance
Copy link
Owner

Things to try:

  • add a pageSize parameter to the recent call, small enough to avoid limiting from one batch of chats (not sure if this endpoint accepts it or not)
  • comment out the group chat lookup, which will skip filling in most fields (admins, members, etc.) but should be sufficient for reading messages and only incur one API request when fetching recent chats

@eth
Copy link

eth commented Mar 19, 2025

From watching Skype for Web, it doesn't look like it listens for events any more?

If you receive a message while a different chat is selected, the message doesn't come through. After a while (e.g. if you leave the tab in the background and later return to it), the client refreshes the conversation list, notices the chat has been updated, then fetches its messages again to get the new one.

This probably means the long-polling call we use for listening to events doesn't exist in the Teams-backed API (this also lines up with the 501 error, which corresponds to HTTP 501 Not Implemented), so skpy.SkypeEventLoop won't work any more unless someone else can spot a suitable replacement.

You can do something similar to Skype for Web and manually poll for updates via SkypeChats.recent() (which tells you which chats to fetch messages from) and SkypeChat.getMsgs() -- both of these should return a list of their respective objects (updated chats or unseen messages) since the last call, or an empty list if nothing's changed in the meantime.

What do you think about re-writing the loop to pull recent chats and iterate through them as if it was an event like how the loop worked with the proper rate limiting. Would this be difficult? I may give it a try, but my code is nowhere near production grade.

@Terrance
Copy link
Owner

As a reminder, this library is not production-grade.

The current implementation of sync-state URLs (so that when you call e.g. getMsgs() a second time, it gives you the next batch) is global, so using this for the event loop will interfere with the ability to call these methods in user code. It probably needs some work to decouple that or otherwise make those safe to call, as well as some careful handling of past messages being pulled through next pages in the absence of new messages.

Pull requests welcome for an alternate event loop implementation.

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

No branches or pull requests

9 participants