Author Topic: With substancePainter 2020.2.2 connecting from maya to jsonPort fails  (Read 2727 times)

Unfortunately my scripts (a bridge from maya to substancePainter) fails with:

ValueError: No JSON object could be decoded

I use the python method Froyok showed in a post once using python from maya.
It always worked but with 2020.2.2 it fails.
I reverted substancePainter to the previous version so i can continue to work comfortably.
But maybe anybody has any idea what might be the issue.
There is no message in the substancePainter log window that would indicate maya making the connection.

Thanks in advance and stay safe.

Hi, i believe you are using the remote scripting capability of Substance Painter.
Can you give me details on the payload you are sending to Painter ?
Can you also tell me if Painter and Maya run on the same computer ?

Senior Software Engineer
Substance Painter Team

Hi thank you for replying.

Yes they run on the same computer.

I execute functions in a javascript plugin i wrote using json encoded commands send from maya to bake inside substance painter. Then send the filenames of the saved baked meshmaps as result string back to maya.

That worked fine in substancePainter 2020.2.1 (and most of the previous versions) but stopped working in 2020.2.2.
One of those strings i would send to painter via the jsonPort would be:

createProject( "c:/proj/chain_plane_1.obj", ['c:/proj/chain_element_1.obj', 'c:/proj/ground.obj'], {'outputSize': 1024});setSettings( "common", {'commonParameters': {'Dilation_Width': 6, 'Output_Size': [10, 10], 'Apply_Diffusion': true}, 'detailParameters': {'Use_Low_Poly_Mesh_as_High_Poly_Mesh':false , 'Antialiasing': 'None', 'High_Definition_Meshes': ['c:/proj/chain_element_1.obj', 'c:/proj/ground.obj'], 'Use_Cage':false , 'Low_poly_mesh_suffix': '_low', 'Ignore_backfaces_suffix': '_ignorebf', 'Match': 'Always', 'Ignore_Backface': true, 'Cage_File': '', 'Max_Rear_Distance': 0.001, 'Relative_to_Bounding_Box': true, 'High_poly_mesh_suffix': '_high', 'Average_Normals':false , 'Max_Frontal_Distance': 0.001}});

I only reduced the folderstructure in the previous line (passed image filepaths) so it would be a bit shorter in my post.
At the end i pass project setup parameters as dicts that made it easy to apply inside painter.
The encoded json string (with long image filepaths) would be:

So i don't know if the payload is the issue here because i pass way longer stuff to pre 2020.2.2 versions and it worked.

The errormessage maya prints out is:

#   File "C:\Program Files\Autodesk\Maya2021\Python27\lib\json\", line 382, in raw_decode
#     raise ValueError("No JSON object could be decoded")
# ValueError: No JSON object could be decoded

I still use python2.7 for my python stuff inside maya.

As nobody else seems to have issues with the non-working (at least for me) jsonPort.
Maybe nobody really uses it ?

I only have minimal experience in network programming.
I am trying to figure out now using WebSockets (in c#) to communicate with substancePainter.
Or what would be the most recommended way to communicate with substancePainter ?

Thanks for your effort and stay healthy.
Last Edit: October 24, 2020, 08:30:01 pm

We have the exact same problem. Our scripts work fine in older versions but not 2020.2.2. I think something broke on the substance painter side.

Hi, sorry for the delay,

Since the last version of SP, we check the 'Content-type': 'application/json' header for security reason.

If you don't provide this header, teh call will fail and in this case we don;t return a json response ('this may explain your error message').

Can you please post the you complete post request and the complete response you receive from SP please ?

Senior Software Engineer
Substance Painter Team

This is the header we had,
_HEADERS = {'Content-type': 'text/html', 'Accept': 'application/json'}

We changed it to this:
_HEADERS = {'Content-type': 'application/json'}

This seems to have resolved the issue.

Thanks for the response

Thanks a lot now it works again :).

Have a great day and stay safe.

Hello, sorry for hijacking this topic, we had the same error, changing header helped to make it work again, but the communication is now much slower, even simple command like alg.log() takes almost 2 seconds to print to the console, which means heavier tasks takes long long time.

Before, it was quick and all processing took much shorter time. Maybe it is the header check, which is slowing down the whole communication? Is there anything we can do?

Thanks in advance

Could you share an example ? I don't think we noticed any performance issue on our side.
Don't forget your log file. It can be exported from the Help menu of the software.
Fabrice Piquet aka Froyok. Product Manager, Technical Artist and Documentation at Adobe.

Froyok :

console print was instant on previous version, but now it takes two seconds, so other more demanding tasks takes a lot of time.

import base64
import json
import sys
if sys.version_info >= (3, 0):
    import http.client as http
    import httplib as http

class PainterConn:

    _PAINTER_ROUTE = '/run.json'
    _HEADERS = {'Content-type': 'application/json', 'Accept': 'application/json'}

    def __init__(self, port=60041, host='localhost'):
        self._host = host
        self._port = port

    def _jsonPostRequest(self, route, body):
        connection = http.HTTPConnection(self._host, self._port, timeout=3600)
        connection.request('POST', route, body, self._HEADERS)
        response = connection.getresponse()

        data = json.loads('utf-8'))

        if isinstance(data, bool):
            result = {}
            result['bool'] = data
            return result

        if 'error' in data:
            raise ExecuteScriptError(data['error'])
        return data

    def checkConnection(self):
        connection = http.HTTPConnection(self._host, self._port)
            result = connection.connect()
            return True
            return False

    def runScript(self, script):
        main = base64.b64encode(script.encode('utf-8'))
        return self._jsonPostRequest(self._PAINTER_ROUTE, ('{"js":"' + main.decode('utf-8') + '"}').encode('utf-8'))

class PainterError(Exception):
    def __init__(self, message):
        super(PainterError, self).__init__(message)

class ExecuteScriptError(PainterError):
    def __init__(self, data):
        super(PainterError, self).__init__('An error occured when executing script: {0}'.format(data))

painter_con = PainterConn()

painter_con.runScript('alg.log.{}("{}")'.format('info', 'test_connection'))
Last Edit: November 24, 2020, 12:33:16 pm

We have noticed a significant performance hit on our side as well in the latest upgrade of Painter, regarding the json server port communication.
It's sad that it's slown down so much

Could you guys give me your exact Substance Painter version number as well as if it's a standalone version or a Creative Cloud Enterprise version ?
Don't forget your log file. It can be exported from the Help menu of the software.
Fabrice Piquet aka Froyok. Product Manager, Technical Artist and Documentation at Adobe.