If I'm understanding the error message correctly, this doesn't have anything to do with missing globals. If you try to access a global that doesn't exist, you get a NameError. An UnboundLocalError means that you're trying to access a local variable that is currently unassigned.
Short explanation about Python locals - whether a variable in a function is local or global is determined statically at "compile time". If a variable is assigned to in the function, it is always local, even before the assignment. For example the following code will always produce an UnboundLocalError:
var = "global" def fun(): print(var) # raises UnboundLocalError("local variable 'var' referenced before assignment") var = "local" # var is assigned to in the function, which makes it local - the global variable var is hidden fun()My guess is that you're accidentally using location as a variable name later on in the function. Something like this:
import location def get_direction(): if location.is_authorized(): location = location.get_location() # ... do stuff with the location ... else: print("Location access not allowed!")Because you're assigning to location, every use of location in the function looks up the local variable location - when that happens before it is assigned, you get an UnboundLocalError like the one you posted. The fix for this is to choose a different name for the local variable, so it doesn't conflict with any globals that you want to use.