MahjongRepository / mahjong_soul_api

Python wrapper for the Mahjong Soul (Majsoul) Protobuf objects. It allows to use their API.
72 stars 10 forks source link

Errno 101 and Errno 104 #10

Closed ZJChe closed 1 year ago

ZJChe commented 2 years ago

Hi, I just followed your description in README and tried to connect to MS. The program reported:

root@VM-12-12-ubuntu:~/mahjong_soul_api# python3 example.py -u *****@******* -p ********
2022-07-07 19:25:48 INFO: Version: {'version': '0.10.122.w', 'force_version': '0.10.0.w', 'code': 'v0.10.122.w/code.js'}
2022-07-07 19:25:48 INFO: Config: {'ip': [{'name': 'player', 'region_urls': [{'url': 'https://lb-hw.maj-soul.com/api/v0/recommend_list', 'ob_url': 'wss://live-hw.maj-soul.com/ob'}, {'url': 'https://lb-v2.maj-soul.com/api/v0/recommend_list', 'ob_url': 'wss://ob.maj-soul.com/ob'}, {'url': 'https://lb-cdn.maj-soul.com/api/v0/recommend_list', 'ob_url': 'wss://ob.maj-soul.com/ob'}, {'url': 'https://lb-hw.maj-soul.com/api/v0/recommend_list', 'ob_url': 'wss://live-hw.maj-soul.com/ob'}, {'url': 'https://lb-sy.maj-soul.com/api/v0/recommend_list', 'ob_url': 'wss://live-sy.maj-soul.com/ob'}], 'system_email_url': 'https://api-v2.maj-soul.com'}], 'goods_sheleve_id': 'shelves_001'}
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 969, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/usr/lib/python3.8/asyncio/base_events.py", line 1025, in create_connection
    raise exceptions[0]
  File "/usr/lib/python3.8/asyncio/base_events.py", line 1010, in create_connection
    sock = await self._connect_sock(
  File "/usr/lib/python3.8/asyncio/base_events.py", line 924, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/lib/python3.8/asyncio/selector_events.py", line 496, in sock_connect
    return await fut
  File "/usr/lib/python3.8/asyncio/selector_events.py", line 501, in _sock_connect
    sock.connect(address)
OSError: [Errno 101] Network is unreachable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "example.py", line 181, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "example.py", line 41, in main
    lobby, channel, version_to_force = await connect()
  File "example.py", line 68, in connect
    async with session.get(url + "?service=ws-gateway&protocol=ws&ssl=true") as res:
  File "/usr/local/lib/python3.8/dist-packages/aiohttp/client.py", line 1117, in __aenter__
    self._resp = await self._coro
  File "/usr/local/lib/python3.8/dist-packages/aiohttp/client.py", line 520, in _request
    conn = await self._connector.connect(
  File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 535, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 892, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 1051, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 1020, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 975, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host lb-v2.maj-soul.com:443 ssl:default [Network is unreachable]

Before showing these errors, the program stuck at line 4 for about a minute.

Then I saw an issue talking about updating the module, so I did:

pip install ms-api==0.10.103

And ran the program again. This time the program directly jumps out and reported:

root@VM-12-12-ubuntu:~/mahjong_soul_api# python3 example.py -u *******@******** -p ********
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 969, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/usr/lib/python3.8/asyncio/base_events.py", line 1050, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/usr/lib/python3.8/asyncio/base_events.py", line 1080, in _create_connection_transport
    await waiter
  File "/usr/lib/python3.8/asyncio/selector_events.py", line 848, in _read_ready__data_received
    data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "example.py", line 181, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "example.py", line 41, in main
    lobby, channel, version_to_force = await connect()
  File "example.py", line 56, in connect
    async with session.get("{}/1/version.json".format(MS_HOST)) as res:
  File "/usr/local/lib/python3.8/dist-packages/aiohttp/client.py", line 1117, in __aenter__
    self._resp = await self._coro
  File "/usr/local/lib/python3.8/dist-packages/aiohttp/client.py", line 520, in _request
    conn = await self._connector.connect(
  File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 535, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 892, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 1051, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 1020, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 975, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host game.maj-soul.net:443 ssl:default [Connection reset by peer]

I wonder what I could do to push it forward, many thanks!

ZJChe commented 2 years ago

By the way, MS CN server changed its url link about 1 or 2 months ago, so I changed line 21:

MS_HOST = "https://game.maj-soul.com"

to:

MS_HOST = "https://game.maj-soul.net"

Before changing this line, the program reported Errno 101:

aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host game.maj-soul.com:443 ssl:default [Network is unreachable]
ZJChe commented 2 years ago

More observations:

The json file read by executing line 62: https://game.maj-soul.net/1/v0.10.122.w/config.json, is:

{"ip":[{"name":"player","region_urls":[
{"url":"https://lb-hw.maj-soul.com/api/v0/recommend_list","ob_url":"wss://live-hw.maj-soul.com/ob"},
{"url":"https://lb-v2.maj-soul.com/api/v0/recommend_list","ob_url":"wss://ob.maj-soul.com/ob"},
{"url":"https://lb-cdn.maj-soul.com/api/v0/recommend_list","ob_url":"wss://ob.maj-soul.com/ob"},
{"url":"https://lb-hw.maj-soul.com/api/v0/recommend_list","ob_url":"wss://live-hw.maj-soul.com/ob"},
{"url":"https://lb-sy.maj-soul.com/api/v0/recommend_list","ob_url":"wss://live-sy.maj-soul.com/ob"}
],"system_email_url":"https://api-v2.maj-soul.com"}],"goods_sheleve_id":"shelves_001"}

Here we have 4 different urls, and at line 66 the code chose the second one. I tried all different urls, but whichever one I chose, I got a similar result at line 68:

{"servers":["gateway-sy.maj-soul.com:443"]}
Nihisil commented 1 year ago

Are you able to ping these URLs at all? It looks like an issue with connection between you and MS hosts