jssimporter / python-jss

python-jss is deprecated. Please see the wiki for alternatives.
GNU General Public License v3.0
102 stars 41 forks source link

UnboundLocalError: local variable 'prefs' referenced before assignment #57

Closed ftiff closed 7 years ago

ftiff commented 7 years ago

Got this error with latest release:

[fti@gramont generate_report (master)]$ ./generate.sh 
Traceback (most recent call last):
  File "/root/generate_report.py", line 12, in <module>
    jss_prefs = jss.JSSPrefs()
  File "/usr/local/lib/python2.7/site-packages/jss/jss_prefs.py", line 125, in __init__
    self.parse_plist(self.preferences_file)
  File "/usr/local/lib/python2.7/site-packages/jss/jss_prefs.py", line 154, in parse_plist
    self.user = prefs.get("jss_user")
UnboundLocalError: local variable 'prefs' referenced before assignment

FYI I fixed this by converting the plist from binary to xml with plutil -convert xml1 ~/Library/Preferences/com.github.sheagcraig.python-jss.plist

sheagcraig commented 7 years ago

Hey @ftiff. When running your generate script, does it do so with a python that has pyobjc available? /usr/bin/python will have it; but any virtualenv or other python2 that you have will not by default.

That being said, it's supposed to fall back to importing plistlib and trying to do a plutil -convert on the file and try reading it again.

Is your script catching exceptions and hiding any that may have been raised while it was trying to read the prefs?

sheagcraig commented 7 years ago

To get this error, the parse_plist code would have to have neither PyObjC nor success converting the plist from binary to xml1 and parsing using the stdlib plistlib.

Still an issue?