Problem querying using streamlit

Hi, I get the following error when I connect my code to streamlit but runs perfectly fine when used locally:

ForbiddenException: (403) Reason: Forbidden HTTP response headers: HTTPHeaderDict({‘Content-Length’: ‘50’, ‘content-type’: ‘text/plain’, ‘date’: ‘Fri, 22 Dec 2023 21:39:35 GMT’, ‘server’: ‘envoy’, ‘Via’: ‘1.1 google’, ‘Alt-Svc’: ‘h3=“:443”; ma=2592000,h3-29=“:443”; ma=2592000’, ‘Connection’: ‘close’}) HTTP response body: Project in subdomain didn’t match API keys project.

Interestingly, I get this error when I query for the second time and not the first time.

Hi @heetsakaria. That doesn’t look like a Pinecone error. The error you’ll get with a missing or incorrect API key on Pinecone is

>>> pinecone.init(api_key="this is bad",environment="us-central1-gcp")
>>> pinecone.list_indexes()
Traceback (most recent call last):
...
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'www-authenticate': 'API key is missing or invalid for the environment "us-central1-gcp". Check that the correct environment is specified.', 'content-length': '117', 'date': 'Fri, 22 Dec 2023 22:33:23 GMT', 'server': 'envoy'})
HTTP response body: API key is missing or invalid for the environment "us-central1-gcp". Check that the correct environment is specified.

Importantly, Pinecone consistently refers to the cloud regions where you host your projects as “environment,” not as a project in a subdomain.

I also checked our Github and can’t find that string anywhere. But I did find the sample I posted above in the code for our control plane, which is the part of the system that would be returning any 401s or 403s.

Can you post the full stacktrace you’re getting? That’ll help narrow down where the error is coming from. I’d love to get to the bottom of this because I’ve seen this same error crop up a few times, but I haven’t been able to reproduce it yet. So, the more information you can share, the better I’ll be able to help you as well as the other folks who have run into this.

1 Like

sure here you go:

2023-12-22 16:39:36.278 Uncaught app exception
Traceback (most recent call last):
File “g:\insurancegpt\env\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py”, line 534, in _run_script
exec(code, module.dict)
File “G:\InsuranceGPT\home.py”, line 104, in
bot_response = chatbot.ask(user_input)
File “G:\InsuranceGPT\inference.py”, line 78, in ask
content=self.augment_prompt(query)
File “G:\InsuranceGPT\inference.py”, line 62, in augment_prompt
results = self.vectorstore.similarity_search(query, k=3)
File “g:\insurancegpt\env\lib\site-packages\langchain_community\vectorstores\pinecone.py”, line 229, in similarity_search
docs_and_scores = self.similarity_search_with_score(
File “g:\insurancegpt\env\lib\site-packages\langchain_community\vectorstores\pinecone.py”, line 174, in similarity_search_with_score
return self.similarity_search_by_vector_with_score(
File “g:\insurancegpt\env\lib\site-packages\langchain_community\vectorstores\pinecone.py”, line 191, in similarity_search_by_vector_with_score
results = self._index.query(
File “g:\insurancegpt\env\lib\site-packages\pinecone\core\utils\error_handling.py”, line 17, in inner_func
File “g:\insurancegpt\env\lib\site-packages\pinecone\index.py”, line 455, in query
response = self._vector_api.query(
File “g:\insurancegpt\env\lib\site-packages\pinecone\core\client\api_client.py”, line 776, in call
return self.callable(self, *args, **kwargs)
File “g:\insurancegpt\env\lib\site-packages\pinecone\core\client\api\vector_operations_api.py”, line 716, in __query
return self.call_with_http_info(**kwargs)
File “g:\insurancegpt\env\lib\site-packages\pinecone\core\client\api_client.py”, line 838, in call_with_http_info
return self.api_client.call_api(
File “g:\insurancegpt\env\lib\site-packages\pinecone\core\client\api_client.py”, line 413, in call_api
return self.__call_api(resource_path, method,
File “g:\insurancegpt\env\lib\site-packages\pinecone\core\client\api_client.py”, line 207, in __call_api
raise e
File “g:\insurancegpt\env\lib\site-packages\pinecone\core\client\api_client.py”, line 200, in __call_api
response_data = self.request(
File “g:\insurancegpt\env\lib\site-packages\pinecone\core\client\api_client.py”, line 459, in request
return self.rest_client.POST(url,
File “g:\insurancegpt\env\lib\site-packages\pinecone\core\client\rest.py”, line 271, in POST
return self.request(“POST”, url,
File “g:\insurancegpt\env\lib\site-packages\pinecone\core\client\rest.py”, line 222, in request
raise ForbiddenException(http_resp=r)
pinecone.core.client.exceptions.ForbiddenException: (403)
HTTP response headers: HTTPHeaderDict({‘Content-Length’: ‘50’, ‘content-type’: ‘text/plain’, ‘date’: ‘Fri, 22 Dec 2023 21:39:35 GMT’, ‘server’: ‘envoy’, ‘Via’: ‘1.1 google’, ‘Alt-Svc’: ‘h3=“:443”; ma=2592000,h3-29=“:443”; ma=2592000’, ‘Connection’: ‘close’})
HTTP response body: Project in subdomain didn’t match API keys project

Thanks @heetsakaria. Did you already confirm the API key you’re using matches the project your index is in?

Yes already, confirmed it. After, looking through the internet it’s a common problem with stream-lit. Let me know if you find any solution

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.