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":d],"source":Â]},"history":"","services":
## i{"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":r{"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":e{"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":
          e{
              "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(respu'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