DarkCat09 / python-aternos

[UNMAINTAINED] Unofficial Aternos API written in Python
https://pypi.org/project/python-aternos/
Apache License 2.0
92 stars 13 forks source link

KeyError when trying to get server info #78

Open deedtm opened 1 year ago

deedtm commented 1 year ago

эта ошибка появляется всегда, когда пытаюсь получить какую-либо информацию о сервере, причем сами сервера как объект AternosServer выдаются. залез в сурс код и с помощью принта узнал, что self._info всегда является пустым словарем. photo_2023-06-01_19-53-09 photo_2023-06-01_19-55-18

deedtm commented 1 year ago

code:

class Aternos:
    def __init__(self, username, hashed_password):
        aternos_client = Client()
        aternos_client.login_hashed(username=username, md5=hashed_password)

        self.at = aternos_client.account
        self.servers = aternos_client.account.servers

      def get_server_by_subdomain(self, subdomain):
        at = self.at
        servers = self.servers
        print(servers)

        for server in servers:
            print(server.subdomain)
            if server.subdomain == subdomain:
                try:
                    server.fetch()

                except requests.exceptions.HTTPError:
                    at.atconn.parse_token()
                    self.get_server_by_subdomain(subdomain)

                return server

        return None
DarkCat09 commented 1 year ago

@deedtm,

Call server.fetch() before getting any data from the _info dictionary.
Formerly, there was an "autoparsing" feature: the dictionary was requested automatically on creating AternosServer object. But now, due to Aternos API updates, python-aternos parses an HTML page to load _info that takes some time and resources, so I'm going to implement that feature through autoparse field in AternosClient and/or AternosAccount that will be disabled by default.

Выполняйте server.fetch() перед получением любых данных из словаря _info.
Раньше был функционал "автопарсинга": словарь автоматически запрашивался по АПИ при создании объекта сервера — AternosServer. Но теперь (после обновления АПИ атерноса) модуль парсит целую хтмл-страницу для получения словаря с инфой, что немного дольше и требует чуть больше ресурсов. Собираюсь тот функционал реализовать через поле autoparse в AternosClient и/или AternosAccount, что по дефолту будет выключено.

DarkCat09 commented 1 year ago

TODO:

TechDudie commented 1 year ago

@deedtm,

Call server.fetch() before getting any data from the _info dictionary. Formerly, there was an "autoparsing" feature: the dictionary was requested automatically on creating AternosServer object. But now, due to Aternos API updates, python-aternos parses an HTML page to load _info that takes some time and resources, so I'm going to implement that feature through autoparse field in AternosClient and/or AternosAccount that will be disabled by default.

Выполняйте server.fetch() перед получением любых данных из словаря _info. Раньше был функционал "автопарсинга": словарь автоматически запрашивался по АПИ при создании объекта сервера — AternosServer. Но теперь (после обновления АПИ атерноса) модуль парсит целую хтмл-страницу для получения словаря с инфой, что немного дольше и требует чуть больше ресурсов. Собираюсь тот функционал реализовать через поле autoparse в AternosClient и/или AternosAccount, что по дефолту будет выключено.

i had to go into the library itself and manually enable the autofetch option in the AternosServer class ;-;