NetBox: UnboundLocalError When Syncing Data Source

While working on integrating a new data source in NetBox, I encountered an UnboundLocalException error. This article documents my troubleshooting steps to resolution.
NetBox: UnboundLocalError When Syncing Data Source

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!

About the author

Arapi Tech

Networking + DevOps + Programming

Arapi Tech Blog

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Arapi Tech Blog.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.