poljar/weechat-matrix

python: stdout/stderr (matrix): KeyError: 'invite' in receive_cb in matrix.py refuses to work

kenrestivo opened this issue · 4 comments

  __ | /| / /_  _ \  _ \  /    __  __ \  __ `/  __/
  __ |/ |/ / /  __/  __/ /___  _  / / / /_/ // /_  
  ____/|__/  \___/\___/\____/  /_/ /_/\__,_/ \__/  
WeeChat 3.0 [compiled on Nov 21 2020 07:34:12]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
python: script "queue" already registered (register ignored)
python scripts loaded: queue
lua scripts loaded: urlselect
Plugins loaded: alias, buflist, charset, exec, fifo, fset, irc,
logger, lua, perl, python, relay, ruby, script, spell, trigger, xfer
python: loading script
"/home/lken/.weechat/python/autoload/matrix.py"
python: unable to register script "queue" (another script already
exists with this name)
python: registered script "matrix", version 0.3.0 (matrix chat
plugin)
matrix: Connecting to matrix.org:443 (SSL)...
matrix: Doing SSL handshake...
matrix: Connected using TLSv1.3, and 256 bit TLS_AES_256_GCM_SHA384
cipher suite.
matrix: received certificate
 - certificate info:
    - subject: commonName=www.matrix.org, serial number
        03D7D9C90EDD909BAC95C415035387B86F90
    - issuer: countryName=US, organizationName=Let's Encrypt,
        commonName=R3
    - key info: RSA key 4096 bits, signed using
        sha256WithRSAEncryption
    - period of validity:
        Begins on:  Sep  2 08:33:06 2021 GMT
        Expires on: Dec  1 08:33:05 2021 GMT
    - fingerprints:
        SHA1:
DB:45:20:B9:46:66:42:4B:8C:3A:17:B2:DD:FE:9F:D2:01:67:DA:0F
        SHA256: 4B:FE:C2:DB:E9:2B:7C:DE:AA:61:DA:B5:6D:19:04:05:EB:6
F:C9:8A:33:6E:A5:D6:DF:10:A0:F4:F0:D2:BE:E9
matrix: Logging in...
matrix: Logged in as @foobar:matrix.org
python: stdout/stderr (matrix): Traceback (most recent call last):
python: stdout/stderr (matrix):   File "/home/lken/.weechat/python/matrix/utf.py", line 89, in wrapper
python: stdout/stderr (matrix):     return function(*args, **kwargs)
python: stdout/stderr (matrix):   File "/home/lken/.weechat/python/autoload/matrix.py", line 334, in receive_cb
python: stdout/stderr (matrix):     response =
server.client.next_response()
python: stdout/stderr (matrix):   File "/usr/local/lib/python3.9/dist-packages/nio/client/http_client.py", line 1342, in next_response
python: stdout/stderr (matrix):     response = self._create_response(
python: stdout/stderr (matrix):   File "/usr/local/lib/python3.9/dist-packages/nio/client/http_client.py", line 1277, in _create_response
python: stdout/stderr (matrix):     response = request_class.from_dict(parsed_dict, *extra_data)
python: stdout/stderr (matrix):   File "/usr/local/lib/python3.9/dist-packages/nio/responses.py", line 170, in wrapper
python: stdout/stderr (matrix):     return f(cls, parsed_dict, *args, **kwargs)
python: stdout/stderr (matrix):   File "/usr/local/lib/python3.9/dist-packages/nio/responses.py", line 1745, in from_dict
python: stdout/stderr (matrix):     rooms = SyncResponse._get_room_info(parsed_dict["rooms"])
python: stdout/stderr (matrix):   File "/usr/local/lib/python3.9/dist-packages/nio/responses.py", line 1688, in _get_room_info
python: stdout/stderr (matrix):     for room_id, room_dict in
parsed_dict["invite"].items():
python: stdout/stderr (matrix): KeyError: 'invite'
python: error in function "receive_cb"

python 3.9.0+
weechat 3.0-1
weechat-matrix latest from git head abe85ed commit

aiofiles==0.6.0
aiohttp==3.7.4.post0
aiohttp-socks==0.6.0
async-timeout==3.0.1
atomicwrites==1.4.0
attrs==21.2.0
cachetools==4.2.4
certifi==2021.10.8
cffi==1.15.0
chardet==4.0.0
charset-normalizer==2.0.7
cryptography==35.0.0
future==0.18.2
h11==0.12.0
h2==4.1.0
hpack==4.0.0
hyperframe==6.0.1
idna==3.3
jsonschema==3.2.0
Logbook==1.5.3
matrix-nio==0.18.7
multidict==5.2.0
nio==3.4.2
peewee==3.14.4
pycparser==2.20
pycryptodome==3.11.0
Pygments==2.10.0
pyOpenSSL==21.0.0
pyrsistent==0.18.0
python-magic==0.4.24
python-olm==3.1.3
python-socks==1.2.4
requests==2.26.0
safepickle==0.2.0
six==1.16.0
typing-extensions==3.10.0.2
unpaddedbase64==2.1.0
urllib3==1.26.7
webcolors==1.11.1
yarl==1.7.0

Please update matrix-nio, this is a duplicate of #284.

$  pip3 install -U matrix-nio
...
Requirement already satisfied: matrix-nio in ./.weechat/python/venv/lib/python3.9/site-packages (0.18.7)

It is already updated.

Are you sure weechat-matrix uses the version from /.weechat/python/venv/lib/python3.9/site-packages?

The traceback seems to suggest that it does not use 0.18.7, the line it's complaining about looks different in the latest release: https://github.com/poljar/matrix-nio/blob/master/nio/responses.py#L1697. If you git blame that line you'll se that it's part of 0.18.7.

Aha, thanks! The key was I missed the symlink requirement that venv be in the source directory, not the .weechat directory.

i.e. I have symlinks:

  /home/lken/.weechat/python:
  total used in directory 16 available 30 GiB
  drwxr-xr-x 4 lken lken 4096 Aug 17 20:40 .
  drwxr-xr-x 9 lken lken 4096 Oct 16 19:51 ..
  drwxr-xr-x 2 lken lken 4096 Aug 17 20:44 autoload
  lrwxrwxrwx 1 lken lken   46 Jan  2  2021 matrix -> /home/localkens/misctech/weechat-matrix/matrix
  lrwxrwxrwx 1 lken lken   47 Jan  2  2021 matrix.py -> /home/localkens/misctech/weechat-matrix/main.py
  drwxr-xr-x 4 lken lken 4096 Aug 17 20:40 venv

I needed to put a symlink into the weechat-matrix source directory (weird!) to link back to the .weechat/python/venv

  /home/localkens/misctech/weechat-matrix:
  total used in directory 112 available 30 GiB
  drwxr-xr-x  6 lken lken  4096 Oct 25 21:36 .
  drwx------ 96 lken lken 12288 Oct 18 18:28 ..
  drwxr-xr-x  2 lken lken  4096 Aug 17 20:41 contrib
  -rw-r--r--  1 lken lken   772 Jun 27  2020 Dockerfile
  drwxr-xr-x  8 lken lken  4096 Oct 25 21:36 .git
  -rw-r--r--  1 lken lken    96 Jun 27  2020 .gitignore
  -rw-r--r--  1 lken lken   784 Jun 27  2020 LICENSE
  -rw-r--r--  1 lken lken 23939 Aug 17 20:41 main.py
  -rw-r--r--  1 lken lken  1007 Sep 10  2020 Makefile
  drwxr-xr-x  3 lken lken  4096 Oct 16 18:48 matrix
  -rw-r--r--  1 lken lken 16177 Jun 27  2020 .pylintrc
  -rw-r--r--  1 lken lken   971 Aug 17 20:41 pyproject.toml
  -rw-r--r--  1 lken lken 11647 Oct 16 18:48 README.md
  -rw-r--r--  1 lken lken   196 Mar 15  2021 requirements.txt
  drwxr-xr-x  2 lken lken  4096 Sep 10  2020 tests
  -rw-r--r--  1 lken lken   508 Jun 27  2020 .travis.yml
  lrwxrwxrwx  1 lken lken    31 Oct 25 21:36 venv -> /home/lken/.weechat/python/venv

Not sure how to document this better than you already have done so (if tersely), but it is definitely a gotcha.