Cadair / matrix-appservice-hangouts

A prototype Matrix<->Hangouts appservice written in Python 3.6 using asyncio.
MIT License
12 stars 4 forks source link

Receiving 401 Unauthorized error, even if Hangups is authorized and functional #24

Open Berulacks opened 5 years ago

Berulacks commented 5 years ago

Trying to log in to hangouts via the app service, I'm receiving the following output/error:

======== Running on http://127.0.0.1:5000 ========
(Press CTRL+C to quit)
Exception in callback AppService._connection_successful(user=<appservice_f...serviceid=None)(<Task finishe...authorized',)>)
handle: <Handle AppService._connection_successful(user=<appservice_f...serviceid=None)(<Task finishe...authorized',)>)>
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/events.py", line 145, in _run
    self._callback(*self._args)
  File "/usr/local/lib/python3.6/site-packages/appservice_framework/appservice.py", line 125, in _connection_successful
    conn, serviceid = future.result()
  File "/home/derin/git/matrix-appservice-hangouts/matrix_appservice_hangouts/__main__.py", line 220, in connect_hangouts
    client_session=session)
  File "/home/derin/git/matrix-appservice-hangouts/matrix_appservice_hangouts/hangouts_client.py", line 79, in init_from_refresh_token
    await client.setup()
  File "/home/derin/git/matrix-appservice-hangouts/matrix_appservice_hangouts/hangouts_client.py", line 106, in setup
    await asyncio.gather(*done)
  File "/usr/local/lib/python3.6/site-packages/hangups/client.py", line 138, in connect
    await self._listen_future
  File "/usr/local/lib/python3.6/site-packages/hangups/channel.py", line 191, in listen
    await self._fetch_channel_sid()
  File "/usr/local/lib/python3.6/site-packages/hangups/channel.py", line 257, in _fetch_channel_sid
    res = await self.send_maps([])
  File "/usr/local/lib/python3.6/site-packages/hangups/channel.py", line 233, in send_maps
    'post', CHANNEL_URL, params=params, data=data_dict
  File "/usr/local/lib/python3.6/site-packages/hangups/http_utils.py", line 88, in fetch
    .format(res.status, res.reason)
hangups.exceptions.NetworkError: Request return unexpected status: 401: Unauthorized

Thing is, Hangups itself works fine: I'm able to log in and chat without issue when simply running hangups. I'm using the same refresh token from ~/.cache/hangups/refresh_token.txt.

While troubleshooting I stumbled upon this hangups issue. I've ensured I'm running aiohttp>=3.3,<4 as per its requirements.txt, but still no luck.

I'm on Debian 9.8 and running python 3.6.8.

Anyone else having this issue?

MartijnBraam commented 5 years ago

I got this too, got around this error by using the code from hangups to login:

diff --git a/matrix_appservice_hangouts/hangouts_client.py b/matrix_appservice_hangouts/hangouts_client.py
index c300ddd..04d2ff3 100644
--- a/matrix_appservice_hangouts/hangouts_client.py
+++ b/matrix_appservice_hangouts/hangouts_client.py
@@ -74,7 +74,8 @@ class HangoutsClient:
         """
         Login and make a thing
         """
-        cookies = await cls.login(refresh_token, client_session)
+        #cookies = await cls.login(refresh_token, client_session)
+        cookies = hangups.get_auth_stdin('refresh_token.txt')
         client = cls(cookies, recieve_event_handler, loop=loop, client_session=client_session)
         await client.setup()
         await client.get_self()
@@ -96,7 +97,6 @@ class HangoutsClient:
         Setup stuff that's async
         """
         task = asyncio.ensure_future(self.client.connect())
-
         # Wait for hangups to either finish connecting or raise an exception.
         on_connect = asyncio.Future()
         self.client.on_connect.add_observer(lambda: on_connect.set_result(None))

This makes the login to hangouts successful again except everything crashes for be now because I have old hangouts rooms in my matrix server and every time I restart the bridge it tries to connect more times and that causes database errors.