- Products
- Learn
- Local User Groups
- Partners
- More
What’s New in Device Diagnostics?
Dec 2nd @ 5pm CET / 11am EST
AI Security Masters
Security in the Pace of AI:
From Threat to Force Multiplier
CPX is Back!
Join us in Las Vegas, Vienna, and/or Bangkok!
Check Point Named a Leader
The Forrester Wave:
Enterprise Firewall Solutions, Q4 2026
What’s New in Agentic Network Orchestration
CheckMates Go:
Fun Ding
"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...
I figured it out... My arguments were not inside the "with APIClient(client_args) as client:" block, so those values were getting thrown out. Check your indentation, folks!
Hi @PhoneBoy.
Currently I'm using Python 3.7 with CPAPI 1.0.3, 1.0.3 is the newest version of our API afaik. When I mentioned my framework I just meant the outline I made for my CP API scripts. I'll post my current script below for posterity (I've ripped out dynamic variables, trying to par down unnecessary stuff to find the issue).
import os
import sys
import json
import getpass
from glob import glob
from cpapi import APIClient, APIClientArgs
def main():
apiServer = input("IP:")
username = input("Username: ")
if sys.stdin.isatty():
password = getpass.getpass("Password: ")
else:
print("Getpass failed, you can still enter your password but it will be shown.")
password = input("Password: ")
client_args = APIClientArgs(server=apiServer, api_version="1.3")
with APIClient(client_args) as client:
if client.check_fingerprint() is False:
print("Could not get the server's fingerprint.")
exit(1)
print("\n\tVerifying the type of server {}...".format(apiServer))
if loginRes.success is False:
print("Login failed: {}".format(loginRes.error_message))
exit(1)
session_res = client.api_call("show-session", {}, loginRes.data["sid"])
sid=args.session_id
print(sid)
cwd = os.getcwd()
os.chdir(os.path.join(cwd, "exportedData"))
for file in glob('*.json'):
print("Current file name is: " + str(file))
with open (file, "r") as jsonFile:
json_data=open(file)
jdata = json.load(json_data)
commandName = str(file).split("Export")[0]
addHostResponse = client.api_call('add-host', {'name':'host1','ip-address':'192.168.0.0'})
print(addHostResponse)
publish_res = client.api_call("publish", {})
main()
I figured it out... My arguments were not inside the "with APIClient(client_args) as client:" block, so those values were getting thrown out. Check your indentation, folks!
Leaderboard
Epsum factorial non deposit quid pro quo hic escorol.
| User | Count |
|---|---|
| 1 | |
| 1 |
Tue 24 Nov 2026 @ 01:30 PM (GMT)
La nueva realidad de los ataques DDoS: autonomía, escala y el futuro de la defensaWed 02 Dec 2026 @ 03:30 PM (GMT)
The New DDoS Reality: Autonomy, Scale, and the Future of DefenseThu 03 Dec 2026 @ 11:00 AM (EST)
Under the Hood: Check Point Cloud Firewall for Nutanix - How to Secure your AI WorkloadsTue 24 Nov 2026 @ 01:30 PM (GMT)
La nueva realidad de los ataques DDoS: autonomía, escala y el futuro de la defensaWed 02 Dec 2026 @ 03:30 PM (GMT)
The New DDoS Reality: Autonomy, Scale, and the Future of DefenseThu 03 Dec 2026 @ 11:00 AM (EST)
Under the Hood: Check Point Cloud Firewall for Nutanix - How to Secure your AI WorkloadsAbout CheckMates
Learn Check Point
Advanced Learning
WE SECURE YOUR AI TRANSFORMATION