Keep Running the 401 Error even placed the .ENV file and API Key
As the title stated, I keep getting 401 error even with .ENV and API Key placed correctly.
Asked GPT to see if anything went wrong and it says:
The main function generate_image() does not call get_access_token() — it relies on the token being passed in from outside.
From your traceback earlier:
generate_image(self.access_token, ...)
So, if self.access_token is not loaded via get_access_token(), the .env file is never read.
Then it sugguested to edit the following in nodes.py:
zipped_bytes = generate_image(self.access_token, positive, model, action, params, timeout, retry)
to:
from .utils import get_access_token # Add this at top if not already imported
access_token = get_access_token() zipped_bytes = generate_image(access_token, positive, model, action, params, timeout, retry)
I edited as it says and now it works!
Thanks for your tips. I have a question: where do you put the .env file? I don't know it's exact location. And the .env file is just a text document with the line NAI_ACCESS_TOKEN= My access token, right?
.env should be in "ComfyUI" folder, and set token as
NAI_ACCESS_TOKEN=pst-...