Skip to content

Commit

Permalink
Use the correct text type for upgrade probes in both Python 2 and 3 (#…
Browse files Browse the repository at this point in the history
…101)

Without this, Python 2 chooses binary mode. Fixes #265.
  • Loading branch information
sambrightman authored and miguelgrinberg committed Mar 15, 2019
1 parent 66290a5 commit 4f0b4ea
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion engineio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def _connect_websocket(self, url, headers, engineio_path):
else:
raise exceptions.ConnectionError('Connection error')
if upgrade:
p = packet.Packet(packet.PING, data='probe').encode()
p = packet.Packet(packet.PING, data=six.text_type('probe')).encode()
try:
ws.send(p)
except Exception as e: # pragma: no cover
Expand Down
4 changes: 2 additions & 2 deletions tests/common/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def test_websocket_upgrade_no_pong(self, create_connection):
@mock.patch('engineio.client.websocket.create_connection')
def test_websocket_upgrade_successful(self, create_connection):
create_connection.return_value.recv.return_value = packet.Packet(
packet.PONG, 'probe').encode()
packet.PONG, six.text_type('probe')).encode()
c = client.Client()
c.sid = '123'
c.base_url = 'http://foo'
Expand All @@ -571,7 +571,7 @@ def test_websocket_upgrade_successful(self, create_connection):
self.assertEqual(c.ws, create_connection.return_value)
self.assertEqual(
create_connection.return_value.send.call_args_list[0],
((packet.Packet(packet.PING, 'probe').encode(),),)) # ping
((packet.Packet(packet.PING, six.text_type('probe')).encode(),),)) # ping
self.assertEqual(
create_connection.return_value.send.call_args_list[1],
((packet.Packet(packet.UPGRADE).encode(),),)) # upgrade
Expand Down

0 comments on commit 4f0b4ea

Please sign in to comment.