AWS Thinkbox Discussion Forums

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.

Did you ever have success with this @Gotz_Bongartz?

I need to do a similar thing…

I want to revive this thread as I did not solve it yet. I had a look at this today and it seems like there is an issue with the json-parser of the middleware running on the deadline webservice.

Here is my code:

import requests
import json
url = 'http://localhost:8082/api/jobs'
jobinfo = {
    "JobInfo":
        {
            "UserName": "testuser",
            "Region": "",
            "Frames": "0",
            "Group": "gpu",
            "Pool": "gpu",
            "Blacklist": "",
            "OverrideTaskExtraInfoNames": "False",
            "MachineName": "testuser-MacBook-Pro",
            "Plugin": "Redshift",
            "OutputDirectory0": "/mnt/test/Assets/temp/out.exr",
            "EventOptIns": ""
        }
}
pluginfo = {    
    "PluginInfo": {
            "Version": "1",
            "SceneFile": "/mnt/test/Assets/temp/out.rs",
            "RenderOptionsFile": "",
            "GPUsPerTask": "0",
            "SelectGPUDevices": "",
            "TextureCacheBudget": "0",
            "ImageOutputDirectory": "/mnt/test/Assets/temp/out.exr",
            "OverrideResolution": "false",
            "Width": "800",
            "Height": "600"
        }
}
auxfiles = {
    "AuxFiles": {}
}
idonly = {
    "IdOnly": "false"
}
jobinfo.update(pluginfo)
jobinfo.update(auxfiles)
jobinfo.update(idonly)

#jobinfo = [jobinfo,pluginfo,auxfiles,idonly]

serialized = json.dumps(jobinfo)
json_data = json.loads(serialized)
print(json.dumps(jobinfo, indent=4))
Headers = {'Content-type': 'application/json'}
r = requests.post(url, json=json_data, headers=Headers)
print(r.text)

When I do this, the service sends me this answer:

Error: Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'Newtonsoft.Json.Linq.JArray'. (System.InvalidCastException)

Reading this I change the the json object in my code to an array and then I get this:

Error: Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path ‘’, line 1, position 1. (Newtonsoft.Json.JsonReaderException)

@Deadline Support, please be so kind and have a look at this as I’d really like to get that solved. Submitting via CommandLine is really not the way to go for me anymore.

Hello!

Replace your AuxFiles with an array like this "AuxFiles": []. The error is complaining about failing to cast an object to an array. I’ve tested the change on my local 10.1.16.5 install and the job submits successfully.

Indeed that worked!
This is helping SO MUCH, thank you, Justin.

Privacy | Site terms | Cookie preferences