"Wrong session id [3YtytO9PKqAC0NpHMKxY2TyZtm8Hb_gC9KL0o58XtNI]. Session may be expired. Please check session id and resend the request."
This error started showing up on a new box after making an additional user for API purposes. Here's the relevant code:
import os
import sys
import json
import getpass
from glob import glob
from cpapi import APIClient, APIClientArgs
#rules, ALL network objects
def main():
apiServer = input("IP:")
username = input("Username: ")
if sys.stdin.isatty():
password = getpass.getpass("Password: ")
else:
print("Module getpass failed, you can still enter your password but it will be shown.")
password = input("Password: ")
apiVer = "1.1"
posApi = input("API Version? Please format as #.# If you don't know API version leave blank: ")
#if anything was entered set the API version to that, otherwise leave it default
if len(posApi) > 1:
apiVer = posApi
print(str(apiVer))
#set the client variables for login
client_args = APIClientArgs(server=apiServer, api_version=apiVer)
with APIClient(client_args) as client:
#checks fingerprint, if not there gives user a chance to accept. if user declines exits.
if client.check_fingerprint() is False:
print("Could not get the server's fingerprint.")
exit(1)
#logs into the server using given credentials
loginRes = client.login(username, password)
#if login fails print message, exit.
if loginRes.success is False:
print("Login failed: {}".format(loginRes.error_message))
exit(1)
cwd = os.getcwd()
client_args = APIClientArgs(server=apiServer, api_version=apiVer)
with APIClient(client_args) as client:
As far as I understand it the client_args should be maintaining the SID, meaning on login that should get updated. It doesn't look like that's happening though given the message. The weirdest part is that it was working fine* earlier, and I haven't made any changes. I've attached a screenshot of the output. I should also note I've checked the session list in smartconsole and it's bare, and the logs show the API stays logged in for about 2 seconds.
Edit: I've tried running it from another terminal window (PowerShell) to no avail, so I don't think CMD is just hanging onto errant variables. I've also tried running a similar set of commands through PostMan on the same server with the same credentials and it was successful.
Edit2: I just tried it on a separate box - no dice.
Edit3: I tried another script I wrote, using my same framework, and it executed just fine. Not sure where the hangup is...