Error headers = {"Authorization": f"Bearer {api_token}"} NameError: name 'api_token' is not defined
Hello,How can i resolve this error :headers = {“Authorization”: f"Bearer {api_token}"}NameError: name ‘api_token’ is not definedHere the code :import jsonimport requestsAPI_URL = “https://api-inference.huggingface.co/models/sentence-transformers/all-MiniLM-L6-v2”headers = {“Authorization”: f"Bearer {api_token}"}def query(payload):response = requests.post(API_URL, headers=headers, json=payload)return response.json()data = query({“inputs”: {“source_sentence”: “I’m very happy”,“sentences”:[“I’m filled with happiness”, “I’m happy”]}})Thank you
2023-11-12T14:26:23Z
Hi,Just checking, do you have a variable declared calledapi_token? If not, then it will throw a NameError. You can define an api_token variable with the lineapi_token = "INSERT-API-TOKEN-HERE". Or, you can replace the headers line withheaders = {"Authorization": "Bearer ASHGFsdgfhAurF"}. (Replace the gibberish with your api token.) If you have done this, then that is beyond my fairly basic python knowledge.Hope this helps.