Skip to content

Pull request targeting #24 and #25 #26

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.pyc
/*.egg-info/
/dist/
.idea
12 changes: 10 additions & 2 deletions pusherclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import hashlib
import hmac
import logging
import sys


try:
import simplejson as json
except ImportError:
import json

PY3 = sys.version_info[0] == 3

VERSION = "0.2.0"

Expand All @@ -21,6 +23,12 @@ class Pusher(object):

def __init__(self, key, secure=True, secret=None, user_data=None, log_level=logging.INFO, daemon=True, port=None, reconnect_interval=10):
self.key = key
if PY3:
string_type = str
else:
string_type = basestring
if isinstance(secret, string_type):
secret = secret.encode('utf8')
self.secret = secret
self.user_data = user_data or {}

Expand Down Expand Up @@ -106,7 +114,7 @@ def _generate_private_key(socket_id, key, channel_name, secret):

if socket_id and key and channel_name and secret:
subject = "%s:%s" % (socket_id, channel_name)
h = hmac.new(secret, subject, hashlib.sha256)
h = hmac.new(secret, subject.encode('utf8'), hashlib.sha256)
auth_key = "%s:%s" % (key, h.hexdigest())

return auth_key
Expand All @@ -117,7 +125,7 @@ def _generate_presence_key(socket_id, key, channel_name, secret, user_data):

if socket_id and key and channel_name and secret and user_data:
subject = "%s:%s:%s" % (socket_id, channel_name, json.dumps(user_data))
h = hmac.new(secret, subject, hashlib.sha256)
h = hmac.new(secret, subject.encode('utf8'), hashlib.sha256)
auth_key = "%s:%s" % (key, h.hexdigest())

return auth_key
Expand Down
5 changes: 3 additions & 2 deletions pusherclient/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import websocket
import logging
import time
import ssl

try:
import simplejson as json
Expand Down Expand Up @@ -105,7 +106,7 @@ def _connect(self):
on_close=self._on_close
)

self.socket.run_forever()
self.socket.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})

while self.needs_reconnect and not self.disconnect_called:
self.logger.info("Attempting to connect again in %s seconds."
Expand All @@ -116,7 +117,7 @@ def _connect(self):
# We need to set this flag since closing the socket will set it to
# false
self.socket.keep_running = True
self.socket.run_forever()
self.socket.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})

def _on_open(self, ws):
self.logger.info("Connection: Connection opened")
Expand Down