Terrance/SkPy

Connecting via proxies

Closed this issue · 4 comments

I saw that it is possible to use a proxy as an environment variable. But I would like to be able to pass a proxy as a variable in functions like:

proxy = {
    'http': '127.0.0.1:80',
    'https': '127.0.0.1:80'
}
sk = Skype(user, pwd, proxy, tokenFile=token)

And set proxies in requests.session() inside your classes.

Is it possible to do it? This functionality is needed to work in a multi-thread, in order to install different proxies for each thread.

SkPy relies on requests' automatic proxy detection, so doesn't offer proxy settings of its own. That said, the requests Session object is exposed as sk.conn.sess, so you could assign Session.proxies there.

Thanks for your answer. I tried to set proxies in s.conn.sess.proxies but I have doubts if this works.

def sk_connect(user, pwd, token, proxy=None, timeout=10):
	s = Skype(connect=False)
	s.conn.sess.proxies = proxy
	s.conn.sess.timeout = timeout
	print(s.conn.sess.proxies)
	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

username = '******@outlook.com'
password = '******'
token = 'file'
proxy = {
	'http': 'socks5://***',
	'https': 'socks5://***'
}

sk = sk_connect(username, password, token, proxy)

print(s.conn.sess.proxies) is outputted correctly. But when I specifically change the proxy to wrong, the script does not throw an error. So, as I understand it, the script works without a proxy.

s.conn.sess.proxies = proxy
resp = s.conn.syncStateCall('GET', 'http://api.ipify.org/')
print(resp.text)

outputs proxy IP and when proxy is wrong I get Traceback, it's what I expect to see. I don't understand why this doesn't work in the other requests methods.

finally:
    sk = Skype(user, pwd, tokenFile=token)
return sk

You're setting up a proxied Skype class but then returning a different one without the proxy set.

Exactly, many thanks!