fix grains filter_by function when using salt-ssh

very similar to #18238 and 7975b0a11
Merge branch 'salt-ssh-grains-fix' of https://github.com/slafs/salt into slafs-salt-ssh-grains-fix

Conflicts:
	salt/client/ssh/wrapper/grains.py
Add missign exception import
Merge pull request #18259 from thatch45/slafs-salt-ssh-grains-fix

Merge #18249 with fixes