netdevopsbr / netbox-proxbox

Netbox Plugin for integration between Proxmox and Netbox
Apache License 2.0
321 stars 45 forks source link

'NoneType' object has no attribute 'lower' #106

Open i-pushkin opened 1 year ago

i-pushkin commented 1 year ago

When attempting to retrieve data from the cluster, the following error is displayed

<class 'AttributeError'>

'NoneType' object has no attribute 'lower'

Python version: 3.10.10
NetBox version: 3.4.7

It is not quite clear how to diagnose such an error

AttributeError at /plugins/proxbox/full_update/

'NoneType' object has no attribute 'lower'
Request Method: | GET -- | -- https://netbox.domain.com/plugins/proxbox/full_update/ 4.1.7 AttributeError 'NoneType' object has no attribute 'lower' /opt/netbox/venv/lib/python3.10/site-packages/netbox_proxbox/proxbox_api/updates/virtual_machine.py, line 396, in interfaces_ips netbox_proxbox.views.ProxmoxFullUpdate /opt/netbox/venv/bin/python3 3.10.10 ['/opt/netbox/netbox', '/opt/netbox', '/opt/netbox/venv/bin', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/opt/netbox/venv/lib/python3.10/site-packages'] Mon, 17 Apr 2023 06:14:56 +0000

Request Method: GET
Request URL: https://netbox.domain.com/plugins/proxbox/full_update/

Django Version: 4.1.7
Python Version: 3.10.10
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'corsheaders',
 'debug_toolbar',
 'graphiql_debug_toolbar',
 'django_filters',
 'django_tables2',
 'django_prometheus',
 'graphene_django',
 'mptt',
 'rest_framework',
 'social_django',
 'taggit',
 'timezone_field',
 'circuits',
 'dcim',
 'ipam',
 'extras',
 'tenancy',
 'users',
 'utilities',
 'virtualization',
 'wireless',
 'django_rq',
 'drf_yasg',
 'netbox_proxbox.ProxboxConfig']
Installed Middleware:
['graphiql_debug_toolbar.middleware.DebugToolbarMiddleware',
 'django_prometheus.middleware.PrometheusBeforeMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'netbox.middleware.ExceptionHandlingMiddleware',
 'netbox.middleware.RemoteUserMiddleware',
 'netbox.middleware.LoginRequiredMiddleware',
 'netbox.middleware.DynamicConfigMiddleware',
 'netbox.middleware.APIVersionMiddleware',
 'netbox.middleware.ObjectChangeMiddleware',
 'django_prometheus.middleware.PrometheusAfterMiddleware']

Traceback (most recent call last):
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 56, in inner
    response = get_response(request)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 103, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/contrib/auth/mixins.py", line 109, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 142, in dispatch
    return handler(request, *args, **kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/netbox_proxbox/views.py", line 93, in get
    "virtualmachines_table": VMUpdateResult(proxbox_api.update.all(remove_unused = True)["virtualmachines"]),
  File "/opt/netbox/venv/lib/python3.10/site-packages/netbox_proxbox/proxbox_api/update.py", line 448, in all
    vm_updated = virtual_machine(proxmox_json = px_vm_each)
  File "/opt/netbox/venv/lib/python3.10/site-packages/netbox_proxbox/proxbox_api/update.py", line 278, in virtual_machine
    full_update = vm_full_update(netbox_vm, proxmox_json)
  File "/opt/netbox/venv/lib/python3.10/site-packages/netbox_proxbox/proxbox_api/update.py", line 37, in vm_full_update
    ips_updated = updates.virtual_machine.interfaces_ips(netbox_vm, proxmox_vm)
  File "/opt/netbox/venv/lib/python3.10/site-packages/netbox_proxbox/proxbox_api/updates/virtual_machine.py", line 396, in interfaces_ips
    _mac = interface['mac_address'].lower()

Exception Type: AttributeError at /plugins/proxbox/full_update/
Exception Value: 'NoneType' object has no attribute 'lower'

My guess is that the problem is that my netbox installation already has data that is in conflict.

tpsretard commented 1 year ago

Just did the install and came here to research this error. I am having the same issue.

TallBlondMan commented 8 months ago

Logs from container:
127.0.0.1 - - [17/Nov/2023:13:58:32 +0000] "GET /api/virtualization/interfaces/?virtual_machine_id=625&limit=0 HTTP/1.1" 200 1281 "-" "python-requests/2.31.0" [ERROR] too many results 127.0.0.1 - - [17/Nov/2023:13:58:32 +0000] "GET /api/virtualization/interfaces/?virtual_machine_id=625&limit=0 HTTP/1.1" 200 1281 "-" "python-requests/2.31.0" Internal Server Error: /plugins/proxbox/full_update/ Traceback (most recent call last): File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) ^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, callback_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.11/site-packages/django/views/generic/base.py", line 104, in view return self.dispatch(request, *args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.11/site-packages/django/contrib/auth/mixins.py", line 109, in dispatch return super().dispatch(request, args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.11/site-packages/django/views/generic/base.py", line 143, in dispatch return handler(request, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.11/site-packages/netbox_proxbox/views.py", line 93, in get "virtualmachines_table": VMUpdateResult(proxbox_api.update.all(remove_unused = True)["virtualmachines"]), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.11/site-packages/netbox_proxbox/proxbox_api/update.py", line 448, in all vm_updated = virtual_machine(proxmox_json = px_vm_each) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.11/site-packages/netbox_proxbox/proxbox_api/update.py", line 278, in virtual_machine full_update = vm_full_update(netbox_vm, proxmox_json) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.11/site-packages/netbox_proxbox/proxbox_api/update.py", line 37, in vm_full_update ips_updated = updates.virtual_machine.interfaces_ips(netbox_vm, proxmox_vm) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.11/site-packages/netbox_proxbox/proxbox_api/updates/virtual_machine.py", line 396, in interfaces_ips _mac = interface['mac_address'].lower() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'lower'

So I fought with it for a while on clean install and already populated database - solved for me in both cases.

  1. Clean database:
    Try creating a device and follow all necessary items to create -> Type, Manufacturer, etc Make sure to set:
    'virtualmachine_role_id' : 0,
    'node_role_id' : 0,
    'site_id': 0 And it should work.
  2. For populated database:
    Set the ids to 0 as above and remove any VM that is causing problems (from trace above):
    127.0.0.1 - - [17/Nov/2023:13:58:32 +0000] "GET /api/virtualization/interfaces/?virtual_machine_id=625&limit=0 HTTP/1.1" 200 1281 "-" "python-requests/2.31.0"
    virtual_machine_id=625 - This has to be deleted in Netbox.

Hope it helps