Error: UnboundLocalError
When adding a new Data Source to NetBox, it provides an UnboundLocalError message.
Local Data Source Error:
UnboundLocalError("cannot access local variable '_' where it is not associated with a value")

Remote Git Data Source Error:
UnboundLocalError("local variable '_' referenced before assignment")

Solution
The UnboundLocalError failure occurs when the dulwich
package is missing from the venv environment. To fix this, add dulwich
to the requirements.txt
file, run the upgrade.sh
script, and then restart the NetBox service.
If using Amazon S3 bucket, then boto3
must be added to the requirements.
Source: NetBox OSS 4.0.8 Documentation - Synchronized Data
Add dulwich
and boto3
to Requirements File
printf "dulwich\nboto3\n" | sudo tee -a /opt/netbox/requirements.txt
# or
sudo sh -c "printf 'dulwich\nboto3\n' >> /opt/netbox/requirements.txt"
Exit Venv Then Run Upgrade Script
deactivate
sudo /opt/netbox/upgrade.sh
Restart NetBox Service then Activate Venv
sudo systemctl restart netbox netbox-rq
source /opt/netbox/venv/bin/activate
NetBox should now be able to sync with a local or remote Data Source!