Sending a message in Skype using skpy in python

有些话、适合烂在心里 提交于 2019-12-10 22:15:40

问题


Scenario: I am trying to work out a way to send a quick test message in skype with a python code. From the documentations (https://pypi.python.org/pypi/SkPy/0.1) I got a snippet that should allow me to do that.

Problem: I refilled the information as expected, but I am getting an error when trying to create the connection to skype in:

sk = Skype(username, password)

I get:

SkypeAuthException: ("Couldn't retrieve t field from login response", )

I have no idea what this error means.

Question: Any idea on how to solve this?

Code: This is basically what I am using, plus my username and password:

from skpy import Skype
sk = Skype(username, password) # connect to Skype

sk.user # you
sk.contacts # your contacts
sk.chats # your conversations

ch = sk.contacts["joe.4"].chat # 1-to-1 conversation

ch.sendMsg(content) # plain-text message

Question 2: Is there any way to do this, in which the password and username should not be in the code? For example, would it be possible to use the skype instance that is already open in that computer?


回答1:


It might look like you have been blocked from your server's IP if you logged in elsewhere recently. This works for me.

from skpy import Skype
loggedInUser = Skype("userName", "password")
print(loggedInUser.users)               // loggedIn user info
print(loggedInUser.contacts)            // loggedIn user contacts

PS: skpy version: 0.8.1




回答2:


try this:

def connect_skype(user, pwd, token):
    s = Skype(connect=False)
    s.conn.setTokenFile(token)
    try:
        s.conn.readToken()
    except SkypeAuthException:
        s.conn.setUserPwd(user, pwd)
        s.conn.getSkypeToken()
        s.conn.writeToken()
    finally:
        sk = Skype(user, pwd, tokenFile=token)
    return sk

The token parameter can be a empty file, but you need to create before to use this function. The function will be write in this file the client token.

If you still continue the problem, try to sign in to Skype online, sometimes need to update some information then try again.



来源:https://stackoverflow.com/questions/48344035/sending-a-message-in-skype-using-skpy-in-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!