python-aternos icon indicating copy to clipboard operation
python-aternos copied to clipboard

KeyError when trying to get server info

Open deedtm opened this issue 2 years ago • 4 comments

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

deedtm avatar Jun 01 '23 17:06 deedtm

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

deedtm avatar Jun 01 '23 17:06 deedtm

@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 avatar Jun 01 '23 17:06 DarkCat09

TODO:

  • [ ] Update readme
  • [ ] Update docs

DarkCat09 avatar Jun 01 '23 17:06 DarkCat09

@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 ;-;

TechDudie avatar Jun 30 '23 01:06 TechDudie