Pipeline tutorial python bug/issue

Hello,
I am going through the Shotgrid Pipeline Tutorial. It has all been going well until I got to the part where I am creating a custom maya shader publish plugin. I copied and pasted the provided code but when I run the publish from Maya I get a Validation error. In python the error is “NameError: name ‘unicode’ is not defined.” Line 423 of publish_shader_network.py. The code was copy and pasted from the tutorial code (via git) and a diff shows no difference between my file and the one from git.

When I change unicode in the code to str I get an error ‘a bytes-like object is required, not str’. In other toolkit code I see ‘str’ being used in this case (the notes in the code state that unicode is for py2 and str is used for py3 but it still doesn’t work.

Anyone with stronger python skill than mine know how to make this work. I am guessing that that tutorial was written for py2.

Here is the path to the code:
https://github.com/shotgunsoftware/tk-config-default2/blob/pipeline_tutorial/hooks/tk-multi-publish2/maya/publish_shader_network.py

Line 423

Thanks for any thoughts on this.

For better or worse I have commented out the isinstance(path, unicode) block. The publish is working now. I am still curious if I should in fact be using the isinstance block.

One way is to use the six library if you want to support both py2 and py3 - How to check if variable is string with python 2 and 3 compatibility - Stack Overflow
Where does the error from the second paragraph get thrown? Python 3 is a bit stricter about strings vs bytes.

Thanks for the info on the six library. I’ll dig into.
The error gets thrown to the SG Desktop log file (and probably the SG Desktop but I didn’t look there). At the moment however it’s all running smoothly.

Hello,

Well Shotgrid changed how it resolves paths in newer versions that was made in Python 3.
Now instead of bytes it takes a strings.
This error is just bad defined and returns wrong message.

here is a code that works

def _session_path():
“”"
Return the path to the current session
:return:
“”"
path = cmds.file(query=True, sn=True)

if isinstance(path, bytes):
   path = path.decode('UTF-8')
    

return path

cmds.file is in maya.cmds Python library command for resolving files and as you see it return string.
So ShotGrid’s {project_path}\install\core\python\tank\util\shotgun_path.py file works lstrip and rstrip on strings (It can’t do those commands on bytes, only on Unicode-string types)
So just in case if somehow you get bytes it should decode it into a strings first.

I hope that I was helpful :slight_smile: