I have a simple FME workbench published to our FME server that accepts a .bat file as the only published parameter.
I cannot get the right syntax to get it working from a python request in a standalone python file. The end result will be running an FME server workbench from a QGIS python script tool within the QGIS desktop GUI. The idea is to use the speed of the server to get the results back to the user quicker than running it on their machine.
The result from Python 3, using the example from the FME Server Website (changing fmerest/v2 to fmerest/v3 here: https://playground.fmeserver.com/python-request/):
IDLE Console results:
http://myserver:myport/fmerest/v3/transformations/commands/submit/DataProcessing/RunBatchFile.fmw
Traceback (most recent call last):
File "C:\GIS\Tools\ProjectSpecific\FME Run Workbench\Run Workbench from Python Request.py", line 35, in <module>
r = urllib.request.urlopen(req)
File "C:\Users\aallan.BUROHAPPOLD\AppData\Local\Programs\Python\Python37x64\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\aallan.BUROHAPPOLD\AppData\Local\Programs\Python\Python37x64\lib\urllib\request.py", line 531, in open
response = meth(req, response)
File "C:\Users\aallan.BUROHAPPOLD\AppData\Local\Programs\Python\Python37x64\lib\urllib\request.py", line 641, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Users\aallan.BUROHAPPOLD\AppData\Local\Programs\Python\Python37x64\lib\urllib\request.py", line 569, in error
return self._call_chain(*args)
File "C:\Users\aallan.BUROHAPPOLD\AppData\Local\Programs\Python\Python37x64\lib\urllib\request.py", line 503, in _call_chain
result = func(*args)
File "C:\Users\aallan.BUROHAPPOLD\AppData\Local\Programs\Python\Python37x64\lib\urllib\request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404:
Here's the code:
import json
import urllib.request
import urllib.parse
batchFilePath = "C:\Temp\FME_ProcessingFolder\RunCommand_TravelTime_aallan.bat"
TOKEN = "5cc3a93eb9f63b9c357885b210a02f5d06000797"
#url = "http://myserver:myport/fmerest/v3/repositories/DataProcessing/items/RunBatchFile.fmw"
## The url above when pasted into the browser gives me info on the item:
##{"lastSaveDate":"2020-08-21T16:42:47+01:00","requirements":"","legalTermsConditions":"","usage":"",
## "description":"","resources":[],"datasets":{"destination":[],"source":[]},"history":"","services":
## [{"displayName":"Job Submitter","name":"fmejobsubmitter"}],"title":"","type":"WORKSPACE","userName":
## "admin","buildNumber":20596,"enabled":true,"lastPublishDate":"2020-08-21T16:42:47+01:00","requirementsKeyword":"",
## "fileSize":23054,"lastSaveBuild":"FME(R) 2020.1.0.1 (20200710 - Build 20596 - WIN64)","name":"RunBatchFile.fmw",
## "category":"","parameters":[{"defaultValue":"\\\\srv-gis01\\FME_ProcessingFolder\\QGIS_Analysis2\\aallan_2020-08-21_ConvexHull\\RunCommand_TravelTime_aallan.bat"
## ,"name":"BatFile","description":"Batch File to run the process","model":"string","optional":true,"type":"FILENAME_MUSTEXIST"}]
## ,"properties":[{"name":"FAILURE_TOPICS","attributes":{},"category":"fmejobsubmitter_FMEUSERPROPDATA","value":""},{"name":"NOTIFICATION_WRITER","attributes":{},
## "category":"fmejobsubmitter_FMEUSERPROPDATA","value":""},{"name":"HTTP_DATASET","attributes":{},"category":"fmejobsubmitter_FMEUSERPROPDATA","value":""},
## {"name":"ADVANCED","attributes":{},"category":"fmejobsubmitter_FMEUSERPROPDATA","value":""},{"name":"SUCCESS_TOPICS","attributes":{},
## "category":"fmejobsubmitter_FMEUSERPROPDATA","value":""}]}
url = "http://myserver:myport/fmerest/v3/transformations/commands/submit/DataProcessing/RunBatchFile.fmw"
print (url)
params = {"publishedParameters":
[{
"name": "BatFile",
"value": batchFilePath
}]
}
body = json.dumps(params).encode('utf-8')
headers = {
'Content-Type' : 'application/json',
'Accept' : 'application/json',
'Authorization' : 'fmetoken token={0}'.format(TOKEN)
}
req = urllib.request.Request(url, body, headers)
r = urllib.request.urlopen(req)
print('Request status: ' + str(r))
print('Request status: ' + str(r.status))
resp = r.read()
resp = resp.decode('utf-8')
resp = json.loads(resp)
print(resp)
if r.status == 202:
print('Job ID is {0}'.format(resp['id']))
In the fmerest/apidoc/v3 if looks like this is the command I want:
POST /transformations/submit/< repository >/< workspace >Submit a job for transformation (asynchronous).
But using that form of URL (below) I get a http 403 error.
http://myserver:myport/fmerest/v3/transformations/submit/DataProcessing/RunBatchFile.fmw
Can anyone spot the problem with the syntax?
Thanks