Python Script for Sending Job to webservice

Hi there,

I’m trying to send a basic render-job via python to the webservice, but I’m getting a 500 error:
Web Service - Error: Unexpected character encountered while parsing number: N. Path '', line 1, position 1. (Newtonsoft.Json.JsonReaderException)
Here is my code:

import requests
import json

url = 'http://10.29.144.112:8082/api/jobs'
myDictObj = {"1Name": "Untitled",
        "Jobinfo":{
            'UserName':'goetzmoritz',
            'Region':'',
            'Frames':'0',
            'Group':'gpu',
            'Pool':'gpu',
            'Blacklist':'',
            'PostJobScript':'/mnt/deadline/scripts/myscripts/report.py',
            'ScheduledStartDateTime':'07/05/2020 15:52',
            'OverrideTaskExtraInfoNames':'False',
            'MachineName':'MBP',
            'Plugin':'Redshift',
            'OutputDirectory0':'/Users/test/Downloads/out.exr',
            'EventOptIns':''
            },
        'PluginInfo':{
            'Version':'1',
            'SceneFile':'/home/test/temp/temp.rs',
            'RenderOptionsFile':'',
            'GPUsPerTask':'0',
            'SelectGPUDevices':'',
            'TextureCacheBudget':'0',
            'ImageOutputDirectory':'/home/test/temp/out.exr',
            'OverrideResolution':'false',
            'Width':'800',
            'Height':'600'
            },
        'AuxFiles':{
            },
        'IdOnly': False
        }
serialized= json.dumps(myDictObj, sort_keys=False, indent=0)
print(serialized)
json_data=json.loads(serialized)
Headers = {'Content-type': 'application/json'}
r = requests.post(url, data=json_data, headers=Headers)
print(r)

Any help on that issue and how to submit a very basic job like that would be great.

Thanks!

I don’t know much about the web service/API, but your key named 1Name could probably cause issues on the receiving end, depending on how they deserialize the payload.

Also, seems like a typo, right?

Edit: You are serializing the data, then deserializing it again before sending it over http. That’s not right – whats the logic here?

Hi,

thanks for your answer. Actually the serializing/deserializing was a test if this might be the reason. I tried to send over the dict itself, serialized and deserialized but it did not really change the result.
The “1Name” was a typo which I brought in while pasting my code to the forum, sorry about that.

Here is my actual Code, edited slightly to bring in the different answers from the webservice:

import requests
import json
import time

url = 'http://10.29.144.112:8082/api/jobs'
myDictObj = {"Jobinfo":{
            'UserName':'goetzmoritz',
            'Region':'',
            'Frames':'0',
            'Group':'gpu',
            'Pool':'gpu',
            'Blacklist':'',
            'PostJobScript':'/mnt/deadline/scripts/myscripts/report.py',
            'ScheduledStartDateTime':'07/05/2020 15:52',
            'OverrideTaskExtraInfoNames':'False',
            'MachineName':'Gotzs-MacBook-Pro',
            'Plugin':'Redshift',
            'OutputDirectory0':'/Users/goetzmoritz/Downloads/out.exr',
            'EventOptIns':''
            },
        'PluginInfo':{
            'Version':'1',
            'SceneFile':'/home/test/temp/temp.rs',
            'RenderOptionsFile':'',
            'GPUsPerTask':'0',
            'SelectGPUDevices':'',
            'TextureCacheBudget':'0',
            'ImageOutputDirectory':'/home/test/temp/out.exr',
            'OverrideResolution':'false',
            'Width':'800',
            'Height':'600'
            },
        'AuxFiles':{
            },
        'IdOnly': False
        }
serialized= json.dumps(myDictObj, sort_keys=False, indent=0)
print(serialized)
json_data=json.loads(serialized)
Headers = {'Content-type': 'application/json'}
r = requests.post(url, data=myDictObj, headers=Headers)
print(r)
time.sleep(1)

r = requests.post(url, data=serialized, headers=Headers)
print(r)
time.sleep(1)

r = requests.post(url, data=json_data, headers=Headers)
print(r)

And here the response from the webservice:

Web Service - Web Service listening for connections on port 8082...
Web Service - Received request from: 145.228.13.56
Web Service - Request: POST http://10.29.144.112:8082/api/jobs
Web Service - Found API command: jobs
Web Service - Error: Unexpected character encountered while parsing value: J. Path '', line 0, position 0. (Newtonsoft.Json.JsonReaderException)
Web Service - Web Service listening for requests...
Web Service - Received request from: 145.228.13.56
Web Service - Request: POST http://10.29.144.112:8082/api/jobs
Web Service - Found API command: jobs
Web Service - Web Service listening for requests...
Web Service - Received request from: 145.228.13.56
Web Service - Request: POST http://10.29.144.112:8082/api/jobs
Web Service - Found API command: jobs
Web Service - Error: Unexpected character encountered while parsing value: J. Path '', line 0, position 0. (Newtonsoft.Json.JsonReaderException)
Web Service - Web Service listening for requests...

And here is what the submitter scripts received:

<Response [500]>
<Response [400]>
<Response [500]>

The 400 delivers this response.body:
Error: Must either provide a 'Jobs' list or 'JobInfo', 'PluginInfo' and 'AuxFiles' properties.

But I am providing this. Weird…

Sending the serialized data is definitely the way to go, which you’ve proven here. So that’s good!

As for the 400-error, could it be as simple as changing your Jobinfo key to JobInfo? Again, I know nothing about this api endpoint, but other than that your object structure looks like it should work.