whoamiW
Convex Community3y ago
36 replies
whoami

Passing clerk generated token to python client?

I generated a token from clerk in react and passed it to a Python service

token = ... # passed from clerk in react
convex = ConvexClient(os.environ["CONVEX_URL"])
convex.set_auth(token)
chat = convex.query(
    "chats:get", {'id': Id('chats', input.chat_id)}
) # this line failed


These are errors I got
Traceback (most recent call last):
  File "/Users/miniforge3/envs/askstring/lib/python3.11/site-packages/convex/__init__.py", line 94, in _request
    r.raise_for_status()
  File "/Users/miniforge3/envs/askstring/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://clean-dinosaur-909.convex.cloud/api/query


I am using dev env and I am pretty sure the url I used in both frontend and backend is consistent. And what's more interesting is, when I removed convex.set_auth(token), the code ran through. I am really confused right now, what are we doing with the token if this is not required? Why providing a token will instead lead to the auth failure?
Was this page helpful?