question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnboundLocalError: local variable 'res' referenced before assignment

See original GitHub issue

I get an sporadically error/stacktrace after multiple use of the command “ykman slot calculate -T 2”. Have you any ideas why?

Python Version: 3.6.0 OS: macOS 10.12.3

➜  ~ ykman -v      
YubiKey Manager (ykman) version: 0.3.1
Libraries:
    libykpers 1.17.3
    libu2f-host 1.1.3
    libusb 1.0.21
➜  ~ ykman slot calculate -T 2
Touch your YubiKey...
722158
➜  ~ ykman slot calculate -T 2
Touch your YubiKey...
722158
➜  ~ ykman slot calculate -T 2
Touch your YubiKey...
Traceback (most recent call last):
  File "/usr/local/bin/ykman", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/site-packages/ykman/cli/__main__.py", line 116, in main
    cli(obj={})
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/ykman/cli/slot.py", line 359, in calculate
    click.echo(res)
UnboundLocalError: local variable 'res' referenced before assignment

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
dainnilssoncommented, Mar 29, 2017

The error handling does look wrong though. The inner try catches the error, but if the error code isn’t 4, it falls though to .echo(res) (which is undefined). it should give you a nicer error based on the error code from ykpers.

0reactions
dagheymancommented, Apr 21, 2017

The actual error should be printed now, feel free to install ykman from the repo or wait for the next release to try it out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python 3: UnboundLocalError: local variable referenced ...
In your case, Var1 is considered as a local variable, and it's used before being set, thus the error. To solve this problem,...
Read more >
Local variable referenced before assignment in Python
The Python "UnboundLocalError: Local variable referenced before assignment" occurs when we reference a local variable before assigning a value to it in a ......
Read more >
Python local variable referenced before assignment Solution
The UnboundLocalError: local variable referenced before assignment error is raised when you try to assign a value to a local variable before it ......
Read more >
Local Variable Referenced Before Assignment - STechies
The “local variable referenced before assignment” error occurs when you give reference of a local variable without assigning any value. Example:
Read more >
[SOLVED] Local Variable Referenced Before Assignment
Unboundlocalerror: local variable referenced before assignment occurs when a variable is used before its created. Python does not have the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found