Test Environment:
OS: CentOS 7.6
Python: 3.4
Xdinfo: 1.4.1
xdresourceid: 1.0-2
xdinfo fails with a python error if local is used as the match string for queries when using a python3 interpreter.
$ xdinfo res local
Traceback (most recent call last):
File "./xdinfo", line 33, in <module>
INFO_URL = '/wh1/xdinfo/v{0}/text/xdinfo/cli/{1}'.format(API_VERSION, str.join('/', sys.argv[1:]))
TypeError: sequence item 2: expected str instance, bytes found
This appears to be because in python3 subprocess.communicate returns a bytes class reference instead of a string type.
xdinfo:21: sys.argv[argindex] = subprocess.Popen(['xdresourceid'], stdout=subprocess.PIPE).communicate()[0].rstrip()
In python3
>>> type(subprocess.Popen(['xdresourceid'], stdout=subprocess.PIPE).communicate()[0].rstrip())
<class 'bytes'>
OR
>>> type(subprocess.Popen(['xdresourceid'], stdout=subprocess.PIPE).communicate()[0])
<class 'bytes'>
Where in python2:
>>> type(subprocess.Popen(['xdresourceid'], stdout=subprocess.PIPE).communicate()[0].rstrip())
<type 'str'>
OR
>>> type(subprocess.Popen(['xdresourceid'], stdout=subprocess.PIPE).communicate()[0])
<type 'str'>
The way to fix this, or at least a way to fix this, that works in both python 2 and 3 is to use the decode() method before the rstrip().
sys.argv[argindex] = subprocess.Popen(['xdresourceid'], stdout=subprocess.PIPE).communicate()[0].decode().rstrip()
Tested this with both python2 and python3.
$xdinfo res local
info_resourceid resource_descriptive_name rdr_type
comet.sdsc.xsede.org SDSC Dell Cluster with Intel Haswell Processors (Comet) resource
comet.sdsc.xsede.org SDSC Dell Cluster with Intel Haswell Processors (Comet) compute
Thanks Chris. I applied your suggested fix to SVN for the next release.