Upload_file error

The function upload_file(customer_id: int, corpus_id: int, idx_address: str, jwt_token: str) returns an error:

ERROR:root:REST upload failed with code 404, reason Not Found, text {“httpCode”:404,“internalCode”:404,“details”:“Customer ID is invalid.”,“status”:{“code_”:404,“statusDetail_”:“Customer ID is invalid.”,“memoizedIsInitialized”:1,“unknownFields”:{“fields”:{}},“memoizedSize”:-1,“memoizedHashCode”:0}}

I’m passing my customer_id as an integer.

Hi,

It looks like you are using Python to upload file.
Here is a complete example on how to do it using python:

Please note that your customer_id is a long value and can be copied either from console (see the screenshot below) or from the email that you got when you registered for Vectara.

Hope this helps.

image

Thanks, Amir.

My problem was that I was generating the wrong jwt_token. I’m now using the code below to generate it, but the session statement fails. I got the auth_url from the console. Thanks for your help.

def _get_jwt_token(auth_url: str, app_client_id: str, app_client_secret: str):
“”“Connect to the server and get a JWT token.”“”
token_endpoint = f"{auth_url}/oauth2/token"
session = OAuth2Session(
app_client_id, app_client_secret, scope=“”)
token = session.fetch_token(token_endpoint, grant_type=“client_credentials”)
return token[“access_token”]

jwt_token = _get_jwt_token(auth_url, app_client_id, app_client_secret)

Nabil
+1.415.810.8058

This e-mail is for the sole use of the intended recipient(s). It contains confidential information. If you believe it has been sent to you in error, please notify the sender by reply e-mail and delete the message. Any disclosure, copying, distribution, or use of this information is prohibited by someone other than the intended recipient.

So when you say that session statement fails. I am assuming that the following line is failing:

session = OAuth2Session( app_client_id, app_client_secret, scope=“”)

If that is the case, make sure that your app_client_id and app_client_secret are correct. These are the id and secret of an AppClient that you can create in the console. One more important thing to note is that this AppClient needs to have sufficient privileges to index data into this corpus. An easier way to do this is to make the AppClient a Corpus Admin when you create it (or edit it afterwards to make it a Corpus Admin). Look at the screenshot below:

Thanks. I have the correct app_client_id and app_client_secret. I’m still getting the following error for the session statement when calling _get_jwt_token:

Traceback (most recent call last):
File “/Users/nabiltakla/N3V-engineering/vectara/example/upload_file.py”, line 35, in
jwt_token = _get_jwt_token(auth_url, app_client_id, app_client_secret)
File “/Users/nabiltakla/N3V-engineering/vectara/example/upload_file.py”, line 30, in _get_jwt_token
session = OAuth2Session(
File “/Users/nabiltakla/opt/anaconda3/envs/n3vEnv/lib/python3.9/site-packages/requests_oauthlib/oauth2_session.py”, line 79, in init
self.token = token or {}
File “/Users/nabiltakla/opt/anaconda3/envs/n3vEnv/lib/python3.9/site-packages/requests_oauthlib/oauth2_session.py”, line 128, in token
self._client.token = value
AttributeError: ‘str’ object has no attribute ‘token’

And now, I’m having a problem accessing the Authorization page - it hangs up; a screenshot is attached. I tried to login in, but it doesn’t recognize my customer_id, so I generated a new account, and I still have the same issue. It’d be best if I could retrieve my account - ntakla@me.com.

Screenshot 2022-12-28 at 8.19.10 AM.png

Nabil
+1.415.810.8058

This e-mail is for the sole use of the intended recipient(s). It contains confidential information. If you believe it has been sent to you in error, please notify the sender by reply e-mail and delete the message. Any disclosure, copying, distribution, or use of this information is prohibited by someone other than the intended recipient.

Can you share your _get_jwt_token code alongwith the imports?

Are you trying to log in with email address only or with customerID as well?

import sys
import jwt
import requests
import json
import oauthlib
import oauth2

def _get_jwt_token(auth_url: str, app_client_id: str, app_client_secret: str):
“”“Connect to the server and get a JWT token.”“”
token_endpoint = f"{auth_url}/oauth2/token"
print(token_endpoint)
session = OAuth2Session(
app_client_id, app_client_secret, scope=“”)
token = session.fetch_token(token_endpoint, grant_type=“client_credentials”)
return token[“access_token”]

jwt_token = _get_jwt_token(auth_url, app_client_id, app_client_secret)

I logged in with my email address, and it reported an error that it didn’t recognize my customer_id.

Nabil
+1.415.810.8058

This e-mail is for the sole use of the intended recipient(s). It contains confidential information. If you believe it has been sent to you in error, please notify the sender by reply e-mail and delete the message. Any disclosure, copying, distribution, or use of this information is prohibited by someone other than the intended recipient.

It looks like you are using this library.

The example I linked above was written using the following library:

That’s why the OAuth2Session arguments are different and you are getting that AttributeError.

I would suggest you install the Authlib and import OAuth2Session the way it is done in the following code:

You can also take a look at requirements.txt to see the exact libs and their versions that are needed to run the example code:

Thanks, Amir. I’ll try it later today.

Nabil
+1.415.810.8058

This e-mail is for the sole use of the intended recipient(s). It contains confidential information. If you believe it has been sent to you in error, please notify the sender by reply e-mail and delete the message. Any disclosure, copying, distribution, or use of this information is prohibited by someone other than the intended recipient.

That worked. Thanks, Amir.

Nabil
+1.415.810.8058

This e-mail is for the sole use of the intended recipient(s). It contains confidential information. If you believe it has been sent to you in error, please notify the sender by reply e-mail and delete the message. Any disclosure, copying, distribution, or use of this information is prohibited by someone other than the intended recipient.

Hi Amir,

How do I check if the file was uploaded? Thanks.

Nabil
+1.415.810.8058

This e-mail is for the sole use of the intended recipient(s). It contains confidential information. If you believe it has been sent to you in error, please notify the sender by reply e-mail and delete the message. Any disclosure, copying, distribution, or use of this information is prohibited by someone other than the intended recipient.

I just wanted to chime in to say thanks for the feedback, Nabil! We’ll look at how we can make the onboarding experience more fluid.

Regarding how to check if the file was uploaded, you should be able to do that in the search console (https://console.vectara.com) by searching for some key terms/concepts you would expect in the file you uploaded. Alternatively, you should be able to use the filter expressions to filter down to only the document that’s of interest to you by adding a filter expression of something like doc.id = 'your_doc.txt'

Thanks, Shane!

Nabil

This e-mail is for the sole use of the intended recipient(s). It contains confidential information. If you believe it has been sent to you in error, please notify the sender by reply e-mail and delete the message. Any disclosure, copying, distribution, or use of this information is prohibited by someone other than the intended recipient.