pixie icon indicating copy to clipboard operation
pixie copied to clipboard

pixie python API client always failed to validate the apikey

Open everestplusteam opened this issue 6 months ago • 8 comments

Describe the bug I tried to connect self-hosted cloud with python API, and followed the instruction to generate apikey and cluster ID. but the python sample code always failed with below errors: Traceback (most recent call last): File "/root/pixie-api-example/main.py", line 26, in main() ~~~~^^ File "/root/pixie-api-example/main.py", line 9, in main conn = px_client.connect_to_cluster('a355537a-8962-4b28-94ee-64e34479e912') File "/root/pixie-api-example/.venv/lib/python3.13/site-packages/pxapi/client.py", line 588, in connect_to_cluster cluster_info = self._get_cluster_info(cluster_id) File "/root/pixie-api-example/.venv/lib/python3.13/site-packages/pxapi/client.py", line 555, in _get_cluster_info return self._get_cluster(request)[0] ~~~~~~~~~~~~~~~~~^^^^^^^^^ File "/root/pixie-api-example/.venv/lib/python3.13/site-packages/pxapi/client.py", line 530, in _get_cluster response: cpb.GetClusterInfoResponse = stub.GetClusterInfo(request, metadata=[ ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^ ("pixie-api-key", self._token), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ("pixie-api-client", "python") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ]) ^^ File "/root/pixie-api-example/.venv/lib/python3.13/site-packages/grpc/_channel.py", line 1181, in call return _end_unary_response_blocking(state, call, False, None) File "/root/pixie-api-example/.venv/lib/python3.13/site-packages/grpc/_channel.py", line 1006, in _end_unary_response_blocking raise _InactiveRpcError(state) # pytype: disable=not-instantiable ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.INTERNAL details = "Auth middleware failed: failed to fetch token - unauthenticated" debug_error_string = "UNKNOWN:Error received from peer ipv4:34.102.151.106:443 {created_time:"2025-06-10T10:22:11.997274906+08:00", grpc_status:13, grpc_message:"Auth middleware failed: failed to fetch token - unauthenticated"}"

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem. Please make sure the screenshot does not contain any sensitive information such as API keys or access tokens.

import pxapi

def main(): # Create a Pixie client. px_client = pxapi.Client(token="px-api-03397708-2978-4710-9beb-e40e38096e57") # Connect to cluster. conn = px_client.connect_to_cluster("a355537a-8962-4b28-94ee-64e34479e912")

# Define a PxL query with one output table.
PXL_SCRIPT = """
    import px
    df = px.DataFrame('http_events')[['resp_status','req_path']]
    df = df.head(10)
    px.display(df, 'http_table')
    """
# Execute the PxL script.
script = conn.prepare_script(PXL_SCRIPT)
# Print the table output.
for row in script.results("http_table"):
    print(row["resp_status"], row["req_path"])

if name == "main": main()

Logs Please attach the logs by running the following command:

./px collect-logs

App information (please complete the following information):

  • Pixie version
  • K8s cluster version
  • Node Kernel version
  • Browser version

Additional context Add any other context about the problem here.

everestplusteam avatar Jun 10 '25 02:06 everestplusteam

I tried the apikey with/without the prefix of "px-api-", but all failed. I also unset the system proxy settings, but still no effect.

everestplusteam avatar Jun 10 '25 02:06 everestplusteam

I added server_url to my self-hosted cloud, but failed with no certificaiton. px_client = pxapi.Client(token="px-api-03397708-2978-4710-9beb-e40e38096e57", server_url="dev.withpixie.dev", use_encryption=False)

everestplusteam avatar Jun 10 '25 06:06 everestplusteam

Hi @everestplusteam, can you verify that your API key exists with the px cli. You can do so by running the following command:

$ PX_CLOUD_ADDR=dev.withpixie.dev:443 px api-key lookup
> Enter API Key (won't echo):  <Enter your key in the prompt>

Please provide the output for that command once you've had a chance to run it.

ddelnano avatar Jun 10 '25 13:06 ddelnano

Image

fqsuncn avatar Aug 11 '25 09:08 fqsuncn

it is my output, but I still cannot connect to with my API key.

fqsuncn avatar Aug 11 '25 09:08 fqsuncn

Image

fqsuncn avatar Aug 11 '25 09:08 fqsuncn

Image

fqsuncn avatar Aug 11 '25 09:08 fqsuncn

I resolved the issue, as local cluster used, I need to set the cluster_address instead using the default value.

Image

fqsuncn avatar Aug 12 '25 00:08 fqsuncn