sugarlabs / sugar

Sugar GTK shell
GNU General Public License v3.0
252 stars 240 forks source link

Port to Python 3 - apisocket.py #909

Closed quozl closed 4 years ago

quozl commented 4 years ago

apisocket.py implements a communication channel between a Sugar Web activity and the Sugar shell and Journal. It is an important part of Sugar.

apisocket.py was automatically ported to Python 3 using 2to3. Testing revealed regressions. The regressions revealed the porting was not done by a human. Rather than fix each regression, the port to Python 3 should be repeated using our Python 3 Porting Guide and other guides.

Commits will need to explain the changes and tests so that we can reach consensus.

Reproducer: start and stop a web activity on Sugar 0.116 with gwebsockets 0.7

shell.log contains

1583480569.218756 ERROR dbus.connection: Unable to set arguments (None,) according to signature 's': <class 'TypeError'>: Expected a string or unicode object
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/dbus/connection.py", line 604, in msg_reply_handler
    reply_handler(*message.get_args_list(**get_args_opts))
  File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 401, in _introspect_reply_handler
    self._introspect_execute_queue()
  File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 387, in _introspect_execute_queue
    proxy_method(*args, **keywords)
  File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 137, in __call__
    **keywords)
  File "/usr/lib/python3/dist-packages/dbus/connection.py", line 584, in call_async
    message.append(signature=signature, *args)
TypeError: Expected a string or unicode object
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/jarabe/apisocket.py", line 323, in _message_received_cb
    stream_id = ord(message.data[0])
TypeError: ord() expected string of length 1, but int found
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/jarabe/apisocket.py", line 323, in _message_received_cb
    stream_id = ord(message.data[0])
TypeError: ord() expected string of length 1, but int found
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/dbus/connection.py", line 607, in msg_reply_handler
    *message.get_args_list()))
  File "/usr/lib/python3/dist-packages/jarabe/apisocket.py", line 211, in error_handler
    self._client.send_error(info["close_request"], error)
  File "/usr/lib/python3/dist-packages/jarabe/apisocket.py", line 268, in send_error
    self._session.send_message(json.dumps(response))
  File "/usr/lib/python3.7/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.7/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.7/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.7/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type DBusException is not JSON serializable
shaansubbaiah commented 4 years ago

I'm trying to work on this issue, trying to replace stream_id = ord(message.data[0]) with stream_id = message.data[0]; I'm not sure how to update gwebsockets 0.6 in the SugarLiveBuild to 0.7 .

I have tried:

  1. Cloning the gwebsockets repo to /usr/src and running autogen, make, make install from the toolkit directory
  2. Copying the newer files directly to /usr/lib/python3.7/dist-packages/gwebsockets

Also, assuming either of these did work, using the browse activity should throw the same error?

Please let me know how to go about it. (I have sent a similar message on the IRC a while ago but got disconnected while trying to set it up on my phone in order to keep it on 24/7)

quozl commented 4 years ago

Update gwebsockets in Sugar Live Build by following the same method already used, see https://github.com/sugarlabs/sugar-live-build/blob/master/src/config/hooks/normal/0900-sugar.hook.chroot#L46

I've Ubuntu 20.04 packages of gwebsockets latest in my package archive, if you'd like to use that instead. It is more recent than Sugar Live Build.

No, using the Browse activity has nothing to do with this problem. Browse is not a Sugar Web activity and does not interact with gwebsockets.

The Gears activity is one you might try.

Regarding IRC, don't expect anyone to answer any questions that are more than about an hour old. We don't bother with that, because we usually find people have solved what they were asking about and had neglected to tell us. We use IRC most when two or more people are in attendance. It is not a store-and-forward network like mail or GitHub issues.

shaansubbaiah commented 4 years ago

Thanks, I believe I've managed to fix the type issue after testing it on the gears activity #911

Saumya-Mishra9129 commented 4 years ago

The issue is solved by f1ac684. We may close this now.

quozl commented 4 years ago

Thanks, I agree.