You can iterate only on collection type objects such as arrays or dictionaries. Here you're trying to iterate over a GridContainer which is just a regular object and thus not iterable. The error message is telling you exactly what the problem is.
I'm guessing you want to iterate over GridContainer's children. In that case you should get an array of its children using get_children() method.
for slot in inventory_slots.get_children():
Again, note that get_children() returns an array, which is iterable.
You can check that it is indeed so by:
var slots = inventory_slots.get_children():
print(slots)