TypeError: str expected, not NoneType
I uploaded the code yesterday and it had not problem, but I had the error messages show up today without modifying the code.
The error messages listed below:
TypeError: str expected, not NoneType
Traceback:
File "/home/user/.local/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script
exec(code, module.dict)
File "/home/user/app/app.py", line 80, in
res = starchat(
File "/home/user/app/app.py", line 40, in starchat
os.environ["HUGGINGFACEHUB_API_TOKEN"] = HUGGINGFACEHUB_API_TOKEN
File "/usr/local/lib/python3.10/os.py", line 685, in setitem
value = self.encodevalue(value)
File "/usr/local/lib/python3.10/os.py", line 757, in encode
raise TypeError("str expected, not %s" % type(value).name)
Originally, the old is like this below
from dotenv import load_dotenv
load_dotenv()
HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN')
os.environ["HUGGINGFACEHUB_API_TOKEN"] = HUGGINGFACEHUB_API_TOKEN
It will show the error message above.
I found I can solve the problem by replacing the key directly.
os.environ["HUGGINGFACEHUB_API_TOKEN"] = "xxxxx"
But, it is not save to reveal the key.
Any help would be much appreciated.