How to use Python to execute a RPC

If you want to execute a RPC from an external host using Python, then you should use the following code.

import requests
import json

url='http://localhost/rpc.php'

session = requests.Session()
# Login and get the session cookie.
session.post(url, data=json.dumps({
	'service': 'session',
	'method': 'login',
	'params': {
		'username': 'admin',
		'password': 'xyz'
	}
}))
# Execute a RPC.
response = session.post(url, data=json.dumps({
	'service': 'system',
	'method': 'noop',
	'params': None
}))
print(response.json())
# Logout.
session.post(url, data=json.dumps({
	'service': 'session',
	'method': 'logout',
	'params': None
}))
# This RPC should fail because of an invalid session authentication.
response = session.post(url, data=json.dumps({
	'service': 'system',
	'method': 'noop',
	'params': None
}))
print(response.json())
session.close()

 

New update available

The following changes were made:

openmediavault 3.0.85

  • Update locales.
  • Various improvements in the WebUI.
  • Display auto network interfaces (e.g. bonded and vlan interfaces) in the CLI welcome message.
  • Set a maximum value for the MTU on the WebUI.
  • Allow browser caching WebUI CSS/Javascript/Images.
  • Add Xen virtual disk storage backend.
  • Mantis 0001772: S.M.A.R.T. WebUI shows red light, but all is green when open S.M.A.R.T. details.
  • Mantis 0001777: Memory leak when calling Guru Meditation window.
  • Mantis 0001781: Increase granularity on SSH “Permit root login” setting.
  • Mantis 0001782: BTRFS multi device listing is wrong formatted.

 

New update available

The following changes were made:

openmediavault 3.0.84

  • Various improvements in the WebUI.
  • Get correct CPU information for NanoPi NEO 2.
  • Improve handling of inactive logical volumes.

openmediavault-lvm2 3.2.4

  • Update locales.
  • Display logical volume status.

 

New update available

The following changes were made:

openmediavault 3.0.83

  • Update locales.
  • Improve error dialog with long messages.
  • Fix bug in the Quota::set() RPC.
  • Mantis 0001773: UID_MAX and GID_MAX from login.defs not read.

 

New update available

The following changes were made:

openmediavault 3.0.82

  • Update locales.
  • Various improvements.
  • Make SNMP location and contact fields optional.