Skip to content

Instantly share code, notes, and snippets.

@c-rotte
Created February 20, 2025 19:44
Show Gist options
  • Select an option

  • Save c-rotte/7be0aa7b9f29b28995810c1f994d2223 to your computer and use it in GitHub Desktop.

Select an option

Save c-rotte/7be0aa7b9f29b28995810c1f994d2223 to your computer and use it in GitHub Desktop.
Abort Pending Scan Jobs on HP Printers w/ ESCL
import base64
import json
import time
import xmltodict
import requests
s = requests.session()
s.verify = False
URL = "http://192.168.178.77"
LOGIN = "admin:<password>"
def login():
current_millis = time.time_ns() // 1000000
s.headers.update({
"Authorization": f"Basic {base64.b64encode(LOGIN.encode()).decode()}"
})
res = s.get(URL + "/AuthChk", params={
"_": current_millis
})
if res.status_code != 200:
raise Exception("Failed to login")
def scanner_status() -> dict:
res = s.get(URL + "/eSCL/ScannerStatus")
if res.status_code != 200:
raise Exception("Failed to get scanner status")
return xmltodict.parse(res.text)
login()
status = scanner_status()
print(status)
jobs = status["scan:ScannerStatus"]["scan:Jobs"]["scan:JobInfo"]
if isinstance(jobs, dict):
jobs = [jobs]
for scan_job in jobs:
print(scan_job)
uuid = scan_job["pwg:JobUuid"]
state = scan_job["pwg:JobState"]
if state not in ["Pending"]:
# job is already canceled
continue
print(f"Job {uuid} is in state {state}")
# delete job
res = s.delete(URL + f"/eSCL/ScanJobs/{uuid}")
print(res.status_code)
if res.status_code != 200:
raise Exception("Failed to delete job")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment