ShaneSutro / Vestaboard

An API Wrapper for Vestaboards written in Python
MIT License
54 stars 10 forks source link

Creating a board with local ip/key and validateKey=True results in error #39

Closed natekspencer closed 1 year ago

natekspencer commented 1 year ago

Describe the bug When attempting to create a board with localApi and validateKey, an error message is returned:

.read() is only available when using local API or by using a read/write enabled API key.
Pass "readWrite=True" along with your apiKey to enable readWrite mode.

Steps to reproduce

from vestaboard import Board

try:
    client = Board(localApi={"ip": "10.0.0.100", "key": "someKey"}, validateKey=True)
except Exception as ex:
    print(ex)

Expected behavior readWrite should not need to be passed for localApi

ShaneSutro commented 1 year ago

Hey @natekspencer! So the valdateKey method was only ever intended for the cloud read/write endpoint since it's possible to have an API key that does not have read access. Conversely, all local API keys are read/write by default, so there's no need to validate the key, so I didn't anticipate folks trying to use it here, thus the odd error.

However, while I was looking into this to at least make the error better fit the real reason, I stumbled upon a reason why one would want to validate the API key... namely the local API returns a 200 and a blank message if you use an invalid key rather than throwing an error. With this in mind, I added support to validate the local API key along with a message that displays when validation is successful. If an invalid API key is used and the board returns a blank message, I'm currently just showing a warning since there's a (very unlikely) case where the key is valid and the board is just actually empty, so I didn't want to throw an error and stop execution in that case. Let me know if this resolves the issue! Fix for this is in v1.2.4, which has been published onto PyPi!