crossbario / crossbario/autobahn-python
ApplicationError fails when mixing python2 and python3
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.5k
- Forks
- 768
- PR merge metrics
- No merged PRs in 30d
Description
I've encountered a crash when using a Python2 router with a Python3 client.
Indeed, when the router send a autobahn.wamp.message.Error containing kwargs the client crashes:
Traceback (most recent call last):
File "/home/emmanuel/projects/autobahn_sync/.tox/py34/lib/python3.4/site-packages/autobahn/wamp/websocket.py", line 90, in onMessage
self._session.onMessage(msg)
File "/home/emmanuel/projects/autobahn_sync/.tox/py34/lib/python3.4/site-packages/autobahn_sync/session.py", line 32, in onMessage
return super(_AsyncSession, self).onMessage(msg)
File "/home/emmanuel/projects/autobahn_sync/.tox/py34/lib/python3.4/site-packages/autobahn/wamp/protocol.py", line 921, in onMessage
txaio.reject(on_reply, self._exception_from_message(msg))
File "/home/emmanuel/projects/autobahn_sync/.tox/py34/lib/python3.4/site-packages/autobahn/wamp/protocol.py", line 248, in _exception_from_message
if msg.kwargs:
TypeError: __init__() keywords must be strings
The trouble is this kwargs's keys are made of bytes (i.e. python2's str) but python3 wants unicode (python3's str) to use them as function parameters
(Pdb) msg.kwargs
{b'message': 'event history for the given subscription is not available or enabled'}
The WAMP spec (https://tools.ietf.org/html/draft-oberstet-hybi-tavendo-wamp-02#section-5.2) only define the utf8-encoded string, I guess then everything should be in UTF-8.
Given there is no trouble when using Python3 everywhere, that mean the data's encoding depends of the sender which I believe is a bug both at serialization (should only send data in one encoding) and deserialization (should only accept data in one encoding) time.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at autobahn/wamp/protocol.py in _exception_from_message and trace the message path from autobahn/wamp/websocket.py's onMessage, then inspect how kwargs are serialized and deserialized between Python 2 and Python 3. Reproduce the mixed-version router/client case with the shown bytes key; done means an Error containing kwargs no longer raises the TypeError and the encoding behavior is consistent with the WAMP string requirement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100