aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2015-09-03 03:59:26 -0400
committerRapptz <[email protected]>2015-09-03 03:59:26 -0400
commit4124b097c708e74dcefad0fdcc5af6e594f1dddc (patch)
tree375c0709ed86216050a2d576297494abe34e0b9f
parentPermissions are now properties rather than functions. (diff)
downloaddiscord.py-4124b097c708e74dcefad0fdcc5af6e594f1dddc.tar.xz
discord.py-4124b097c708e74dcefad0fdcc5af6e594f1dddc.zip
WebSocket gateway now properly uses the auth headers.
-rw-r--r--discord/client.py42
1 files changed, 21 insertions, 21 deletions
diff --git a/discord/client.py b/discord/client.py
index 20b14059..3849c2c4 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -102,25 +102,6 @@ class Client(object):
'on_member_remove': _null_event,
}
- gateway = requests.get(endpoints.GATEWAY)
- if gateway.status_code != 200:
- raise GatewayNotFound()
- gateway_js = gateway.json()
- url = gateway_js.get('url')
- if url is None:
- raise GatewayNotFound()
-
- self.ws = WebSocketClient(url, protocols=['http-only', 'chat'])
-
- # this is kind of hacky, but it's to avoid deadlocks.
- # i.e. python does not allow me to have the current thread running if it's self
- # it throws a 'cannot join current thread' RuntimeError
- # So instead of doing a basic inheritance scheme, we're overriding the member functions.
-
- self.ws.opened = self._opened
- self.ws.closed = self._closed
- self.ws.received_message = self._received_message
-
# the actual headers for the request...
# we only override 'authorization' since the rest could use the defaults.
self.headers = {
@@ -450,8 +431,6 @@ class Client(object):
:param str password: The password used to login.
"""
- self.ws.connect()
-
payload = {
'email': email,
'password': password
@@ -463,6 +442,27 @@ class Client(object):
body = r.json()
self.token = body['token']
self.headers['authorization'] = self.token
+
+ gateway = requests.get(endpoints.GATEWAY, headers=self.headers)
+ if gateway.status_code != 200:
+ raise GatewayNotFound()
+ gateway_js = gateway.json()
+ url = gateway_js.get('url')
+ if url is None:
+ raise GatewayNotFound()
+
+ self.ws = WebSocketClient(url, protocols=['http-only', 'chat'])
+
+ # this is kind of hacky, but it's to avoid deadlocks.
+ # i.e. python does not allow me to have the current thread running if it's self
+ # it throws a 'cannot join current thread' RuntimeError
+ # So instead of doing a basic inheritance scheme, we're overriding the member functions.
+
+ self.ws.opened = self._opened
+ self.ws.closed = self._closed
+ self.ws.received_message = self._received_message
+ self.ws.connect()
+
second_payload = {
'op': 2,
'd': {