crossbario / crossbar

Crossbar.io - WAMP application router
https://crossbar.io/
Other
2.05k stars 274 forks source link

receive machine serial on Mac OS not working #951

Closed markope closed 7 years ago

markope commented 7 years ago

on Python 2 on Mac starting crossbar results in this error:

2017-01-13T18:27:54+0100 [Controller 77602] Traceback (most recent call last): 2017-01-13T18:27:54+0100 [Controller 77602] File "/usr/local/bin/crossbar", line 11, in 2017-01-13T18:27:54+0100 [Controller 77602] load_entry_point('crossbar==16.10.1', 'console_scripts', 'crossbar')() 2017-01-13T18:27:54+0100 [Controller 77602] File "/usr/local/lib/python2.7/site-packages/crossbar-16.10.1-py2.7.egg/crossbar/controller/cli.py", line 1030, in run 2017-01-13T18:27:54+0100 [Controller 77602] options.func(options, reactor=reactor) 2017-01-13T18:27:54+0100 [Controller 77602] File "/usr/local/lib/python2.7/site-packages/crossbar-16.10.1-py2.7.egg/crossbar/controller/cli.py", line 605, in run_command_start 2017-01-13T18:27:54+0100 [Controller 77602] pubkey = node.maybe_generate_key(options.cbdir) 2017-01-13T18:27:54+0100 [Controller 77602] File "/usr/local/lib/python2.7/site-packages/crossbar-16.10.1-py2.7.egg/crossbar/controller/node.py", line 353, in maybe_generate_key 2017-01-13T18:27:54+0100 [Controller 77602] (u'machine-id', _machine_id()), 2017-01-13T18:27:54+0100 [Controller 77602] File "/usr/local/lib/python2.7/site-packages/crossbar-16.10.1-py2.7.egg/crossbar/controller/node.py", line 184, in _machine_id 2017-01-13T18:27:54+0100 [Controller 77602] return plistlib.readPlistFromString(plist_data)["IOPlatformSerialNumber"] 2017-01-13T18:27:54+0100 [Controller 77602] TypeError: list indices must be integers, not str

My version is: Crossbar.io : 16.10.1 Autobahn : 0.17.1 (with JSON, MessagePack, CBOR, UBJSON) Twisted : 16.7.0rc2-KQueueReactor LMDB : 0.89/lmdb-0.9.14 Python : 2.7.11/CPython OS : Darwin-16.1.0-x86_64-i386-64bit Machine : x86_64

In node.py in line 184 it should read

return plistlib.readPlistFromString(plist_data)[0]["IOPlatformSerialNumber"]

instead of

return plistlib.readPlistFromString(plist_data)["IOPlatformSerialNumber"]
oberstet commented 7 years ago

No idea why this didn't pop up earlier .. Hawkie fixed the original issue (and she uses OSX on her dev notebook): https://github.com/crossbario/crossbar/issues/870

I can do the change and hope it works on current and older OSXs - I don't have OSX around ..

markope commented 7 years ago

The suggested fix fixes the issue in my case:

MacBook Pro (Retina, 15', Mitte 2015) Mac OS Sierra 10.12.1

neomanic commented 7 years ago

Can confirm this fix works for me too, Py2.7 on OS X 10.10.

Guessing it was only tested on Py3?

oberstet commented 7 years ago

As mentioned, we don't have a OSX box around to test this, so if anyone can check this out and come up with a patch that works on all Pythons on all OSX versions (as this ping-pong patching gets old), that would be cool!

The relevant bits are here, and the code as it stands is:

elif platform.isMacOSX():
    # Get the serial number of the platform
    import plistlib
    plist_data = subprocess.check_output(["ioreg", "-rd1", "-c", "IOPlatformExpertDevice", "-a"])

    if six.PY2:
        # Only API on 2.7
        return plistlib.readPlistFromString(plist_data)["IOPlatformSerialNumber"]
    else:
        # New, non-deprecated 3.4+ API
        return plistlib.loads(plist_data)[0]["IOPlatformSerialNumber"]
neomanic commented 7 years ago

Here's the patch; which applies solely to Py2.7 on any OS X version.

Also have it in my fork if you'd prefer I do a pull request, but it's so simple I'd prefer not to have to worry about the contributor agreement. I also haven't been able to find how test results should be carried out submitted (with a few minutes of searching); I can do them for at least 2 OS X versions if you can point me in the right direction.

Sorry if I'm dense, but I don't understand why you consider this ping-pong patching. AFAICT it was just an omission in the original plistlib support commit which works fine under Py3, but never would have worked under 2.7.

fix_osx_py27_patch.diff.txt

markope commented 7 years ago

still not fixed in crossbar 17.2.1.