minestat icon indicating copy to clipboard operation
minestat copied to clipboard

[Python] TypeError: string indices must be integers, not 'str'

Open hideki2k02 opened this issue 2 months ago • 2 comments

Expected Behavior

The minestat call should've run as intended with no errors

Actual Behavior/Symptoms

The minestat call causes an exception error

How to Reproduce Behavior/Symptoms

The error seems to happen randomly, fixing itself after a while/after a restart.

MineStat Version

2.6.3

Programming Language and Compiler/Interpreter Version

Python

Operating System

Linux

Output/Screenshot(s)

TypeError: string indices must be integers, not 'str'
ERROR:apscheduler.executors.default:Job "update_schedule (trigger: interval[0:01:00], next run at: 2025-10-23 15:25:03 -03)" raised an exception
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/apscheduler/executors/base.py", line 181, in run_coroutine_job
retval = await job.func(*job.args, **job.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/main.py", line 61, in update_schedule
ms = minestat.MineStat(
^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/minestat/__init__.py", line 317, in __init__
self.json_query()
File "/usr/local/lib/python3.12/site-packages/minestat/__init__.py", line 776, in json_query
return self.__parse_json_payload(payload_raw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/minestat/__init__.py", line 791, in __parse_json_payload
self.version = payload_obj["version"]["name"]
~~~~~~~~~~~^^^^^^^^^^^

Snippet code:

async def update_schedule():
    ms = minestat.MineStat(
        os.getenv('SERVER_IP'),
        int(os.getenv('SERVER_PORT'))
    )
    if ms.online: 
        pass
)

refresh_schedule = AsyncIOScheduler()
refresh_schedule.add_job(update_schedule, 'interval', minutes=1)
refresh_schedule.start()

hideki2k02 avatar Oct 23 '25 18:10 hideki2k02

Hi @hideki2k02 , Welcome to minestat!

Thanks for taking the time to open this issue!

It looks like payload_obj's version key is sometimes (unexpectedly) a string instead of a dict.

It would be helpful for us to be able to replicate this issue. What kind of server are you monitoring with your script (server software/version)? Can you give us the hostname/IP address (if it's publicly reachable)?

I will have a closer look at the code tomorrow :)

mindsolve avatar Oct 23 '25 19:10 mindsolve

Hello! I am monitoring a Minecraft Java 1.7.10 GregTech New Horizon Server. I suppose you could try monitoring with one of the public servers from the GTNH Wiki?

I havent found an debug/verbose mode for minestat, but something tells me that the error could be caused by a timeout error (Or just some throttling of the network, that instead of returning JSON returns a string).

hideki2k02 avatar Oct 24 '25 00:10 hideki2k02