Below is a simple Python 3.x script that can be used to troubleshoot the Moodle course announcement plug-in. To use it, you will need to:
- Install Python 3.0+ on a client computer.
- Copy the script below into a file on the client computer, e.g., xmlrpc-moodle.py.
- Edit serverUrl and server to match your Moodle server configuration.
- Run the script like something like this:
C:\python31\python.exe xmlrpc-moodle.py
# For use with Python 3.x
import sys
import time
import xmlrpc.client
timestamp = time.strftime("%Y-%m-%dT%H:%M:%S") # iso_time
# Server settings
serverUrl = "http://localhost:80/"
server = "moodle199" # can be empty if the serverUrl identifies the server
service = "forum_add_discussion1"
username="admin"
# format and mailnow are hardcoded for now
format=1
mailnow=1
# Announcement settings
courseshortname="CHEM101"
subject="python3 test's subject " + timestamp + ", <a
href=\"http://www.techsmith.com/\">TechSmith!</a>"
message="python3 \"test's\" msg " + timestamp
# RPC call and results
rpcServerUrl = serverUrl + server + "/mnet/xmlrpc/server.php"
service = "mod/forum/rpclib.php/" + service
xmlRpcServer = xmlrpc.client.Server(rpcServerUrl)
print("*** Calling XML-RPC service {0} on server URL {1}".format(service, rpcServerUrl))
try:
result = xmlRpcServer._ServerProxy__request(service, (courseshortname, subject, message, format, username, mailnow))
print("result =", result)
except Exception as e:
print("Unexpected error:", sys.exc_info())
raise