NERSC / NERSC/sfapi_client

Issues with Client initialization from keyfile

Open
#103 2 comments 0 reactions 1 assignee View on GitHub

@tylern4 is already working on this.

Since Oct 24, 2025.

Dominant language
Python
Stars
14
Forks
6
PR merge metrics
No merged PRs in 30d

Description

I created my keyfile as described in the docs.

$ ls -l ~/.superfacility/
total 4
-rw-------+ 1 username group 1693 Oct 24 08:48 key.pem

However, when I initialize a client, several things go wrong.

  1. If no key= argument is given, then client.token is not initialized. I assume the keyfile wasn't found.

  2. Using a key= argument, client.token and client._client_id are set, but client._access_token is missing, and there is no "Authorization" header set.

  3. Submitting a test job gives a hard-to-use error "sfapi_client.exceptions.SfApiError: sbatch: error: Job request does not match any supported policy." It could be right, but it doesn't give a good hint on how to fix my job script / what policy to check.

import os
from pathlib import Path

from sfapi_client import Client
from sfapi_client.compute import Machine

# with Client() as client: # (1.)
keypath = Path(os.environ["HOME"]) / ".superfacility" / "key.pem"
with Client(key=keypath) as client:
    assert client.token is not None # (1.)

    # (2.) The following vars are not setup on construction using key= initialization.
    client._access_token = client.token
    client._http_client().headers.update(
        {"Authorization": "Bearer " + str(client.token)}
    )
    print(client._client_id, client._access_token)
    assert "Authorization" in client._http_client().headers # (2.)
    machine = client.compute(Machine.perlmutter)
    job = machine.submit_job("""#!/bin/bash
#SBATCH -N 2
#SBATCH -t 2
#SBATCH -A m3792
pwd
""") # (3.)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.