TypeError when using the Device Types Import #3417

Closed
opened 2025-12-29 18:28:53 +01:00 by adam · 5 comments
Owner

Originally created by @JustOneMoreDog on GitHub (Feb 26, 2020).

Environment

  • Python version: 3.6.9
  • NetBox version: 2.7.7

Steps to Reproduce

  1. Go to /dcim/device-types/import/
  2. Attempt to import the following
[
    {
        "manufacturer":  "7th Sense",
        "model":  "Delta Media Server",
        "slug":  "Delta-Media-Server",
        "part_number":  "",
        "u_height":  1,
        "is_full_depth":  true,
        "subdevice_role":  "",
        "comments":  ""
    }
]
  1. Get the following error
<class 'TypeError'>

list indices must be integers or slices, not str

Expected Behavior

I expected to be able to bulk import DeviceTypes.

Observed Behavior

All the bulk imports I have done up to this moment have been through CSV and not JSON/YAML so I am not sure if my formatting is correct. I took a CSV of my data and used powershell to convert it to JSON

→ ~\Projects\Inventory\Netbox› gc models_test.csv
manufacturer,model,slug,part_number,u_height,is_full_depth,subdevice_role,comments
7th Sense,Delta Media Server,Delta-Media-Server,,1,true,,
APC,SMX1500RM2U,SMX1500RM2U,,1,true,,
APC,SMX2000RML2U,SMX2000RML2U,,1,true,,
APC,SMX2000RMLV2U,SMX2000RMLV2U,,1,true,,
APC,SMX2000RMLV2UQ,SMX2000RMLV2UQ,,1,true,,
→ ~\Projects\Inventory\Netbox› import-csv models_test.csv | convertto-json | out-file device_types_test.json
→ ~\Projects\Inventory\Netbox› gc device_types_test.json
[
    {
        "manufacturer":  "7th Sense",
        "model":  "Delta Media Server",
        "slug":  "Delta-Media-Server",
        "part_number":  "",
        "u_height":  "1",
        "is_full_depth":  "true",
        "subdevice_role":  "",
        "comments":  ""
    },
    {
        "manufacturer":  "APC",
        "model":  "SMX1500RM2U",
        "slug":  "SMX1500RM2U",
        "part_number":  "",
        "u_height":  "1",
        "is_full_depth":  "true",
        "subdevice_role":  "",
        "comments":  ""
    },
    {
        "manufacturer":  "APC",
        "model":  "SMX2000RML2U",
        "slug":  "SMX2000RML2U",
        "part_number":  "",
        "u_height":  "1",
        "is_full_depth":  "true",
        "subdevice_role":  "",
        "comments":  ""
    },
    {
        "manufacturer":  "APC",
        "model":  "SMX2000RMLV2U",
        "slug":  "SMX2000RMLV2U",
        "part_number":  "",
        "u_height":  "1",
        "is_full_depth":  "true",
        "subdevice_role":  "",
        "comments":  ""
    },
    {
        "manufacturer":  "APC",
        "model":  "SMX2000RMLV2UQ",
        "slug":  "SMX2000RMLV2UQ",
        "part_number":  "",
        "u_height":  "1",
        "is_full_depth":  "true",
        "subdevice_role":  "",
        "comments":  ""
    }
]

I then had to take this and put it into Notepad++ and format it a little (not sure if it was needed but I was trying everything

[
    {
        "manufacturer":  "7th Sense",
        "model":  "Delta Media Server",
        "slug":  "Delta-Media-Server",
        "part_number":  "",
        "u_height":  1,
        "is_full_depth":  true,
        "subdevice_role":  "",
        "comments":  ""
    },
    {
        "manufacturer":  "APC",
        "model":  "SMX1500RM2U",
        "slug":  "SMX1500RM2U",
        "part_number":  "",
        "u_height":  1,
        "is_full_depth":  true,
        "subdevice_role":  "",
        "comments":  ""
    },
    {
        "manufacturer":  "APC",
        "model":  "SMX2000RML2U",
        "slug":  "SMX2000RML2U",
        "part_number":  "",
        "u_height":  1,
        "is_full_depth":  true,
        "subdevice_role":  "",
        "comments":  ""
    },
    {
        "manufacturer":  "APC",
        "model":  "SMX2000RMLV2U",
        "slug":  "SMX2000RMLV2U",
        "part_number":  "",
        "u_height":  1,
        "is_full_depth":  true,
        "subdevice_role":  "",
        "comments":  ""
    },
    {
        "manufacturer":  "APC",
        "model":  "SMX2000RMLV2UQ",
        "slug":  "SMX2000RMLV2UQ",
        "part_number":  "",
        "u_height":  1,
        "is_full_depth":  true,
        "subdevice_role":  "",
        "comments":  ""
    }
]

But when I put this into the Device Type Import, I get the following error
image

Originally created by @JustOneMoreDog on GitHub (Feb 26, 2020). ### Environment * Python version: 3.6.9 * NetBox version: 2.7.7 ### Steps to Reproduce 1. Go to /dcim/device-types/import/ 2. Attempt to import the following ``` [ { "manufacturer": "7th Sense", "model": "Delta Media Server", "slug": "Delta-Media-Server", "part_number": "", "u_height": 1, "is_full_depth": true, "subdevice_role": "", "comments": "" } ] ``` 3. Get the following error ``` <class 'TypeError'> list indices must be integers or slices, not str ``` <!-- What did you expect to happen? --> ### Expected Behavior I expected to be able to bulk import DeviceTypes. <!-- What happened instead? --> ### Observed Behavior All the bulk imports I have done up to this moment have been through CSV and not JSON/YAML so I am not sure if my formatting is correct. I took a CSV of my data and used powershell to convert it to JSON ``` → ~\Projects\Inventory\Netbox› gc models_test.csv manufacturer,model,slug,part_number,u_height,is_full_depth,subdevice_role,comments 7th Sense,Delta Media Server,Delta-Media-Server,,1,true,, APC,SMX1500RM2U,SMX1500RM2U,,1,true,, APC,SMX2000RML2U,SMX2000RML2U,,1,true,, APC,SMX2000RMLV2U,SMX2000RMLV2U,,1,true,, APC,SMX2000RMLV2UQ,SMX2000RMLV2UQ,,1,true,, → ~\Projects\Inventory\Netbox› import-csv models_test.csv | convertto-json | out-file device_types_test.json → ~\Projects\Inventory\Netbox› gc device_types_test.json [ { "manufacturer": "7th Sense", "model": "Delta Media Server", "slug": "Delta-Media-Server", "part_number": "", "u_height": "1", "is_full_depth": "true", "subdevice_role": "", "comments": "" }, { "manufacturer": "APC", "model": "SMX1500RM2U", "slug": "SMX1500RM2U", "part_number": "", "u_height": "1", "is_full_depth": "true", "subdevice_role": "", "comments": "" }, { "manufacturer": "APC", "model": "SMX2000RML2U", "slug": "SMX2000RML2U", "part_number": "", "u_height": "1", "is_full_depth": "true", "subdevice_role": "", "comments": "" }, { "manufacturer": "APC", "model": "SMX2000RMLV2U", "slug": "SMX2000RMLV2U", "part_number": "", "u_height": "1", "is_full_depth": "true", "subdevice_role": "", "comments": "" }, { "manufacturer": "APC", "model": "SMX2000RMLV2UQ", "slug": "SMX2000RMLV2UQ", "part_number": "", "u_height": "1", "is_full_depth": "true", "subdevice_role": "", "comments": "" } ] ``` I then had to take this and put it into Notepad++ and format it a little (not sure if it was needed but I was trying everything ``` [ { "manufacturer": "7th Sense", "model": "Delta Media Server", "slug": "Delta-Media-Server", "part_number": "", "u_height": 1, "is_full_depth": true, "subdevice_role": "", "comments": "" }, { "manufacturer": "APC", "model": "SMX1500RM2U", "slug": "SMX1500RM2U", "part_number": "", "u_height": 1, "is_full_depth": true, "subdevice_role": "", "comments": "" }, { "manufacturer": "APC", "model": "SMX2000RML2U", "slug": "SMX2000RML2U", "part_number": "", "u_height": 1, "is_full_depth": true, "subdevice_role": "", "comments": "" }, { "manufacturer": "APC", "model": "SMX2000RMLV2U", "slug": "SMX2000RMLV2U", "part_number": "", "u_height": 1, "is_full_depth": true, "subdevice_role": "", "comments": "" }, { "manufacturer": "APC", "model": "SMX2000RMLV2UQ", "slug": "SMX2000RMLV2UQ", "part_number": "", "u_height": 1, "is_full_depth": true, "subdevice_role": "", "comments": "" } ] ``` But when I put this into the Device Type Import, I get the following error ![image](https://user-images.githubusercontent.com/42121635/75370784-a468f480-5893-11ea-9eaf-ce498f0ebf14.png)
adam added the pending closure label 2025-12-29 18:28:53 +01:00
adam closed this issue 2025-12-29 18:28:53 +01:00
Author
Owner

@JustOneMoreDog commented on GitHub (Feb 26, 2020):

I continued diving into this issue and I think the main issue is the "manufacturer" field.

I went into the API and adjusted my fields based off of what was there

{
	"manufacturer":  "7th Sense",
	"model":  "Delta Media Server",
	"slug":  "Delta-Media-Server",
	"part_number":  "",
	"u_height":  1,
	"is_full_depth":  true,
	"subdevice_role":  "parent",
	"tags":  [],
	"comments":  {}
}

This of course required more adjustments to my CSV

manufacturer,model,slug,part_number,u_height,is_full_depth,subdevice_role,tags,comments
7th Sense,Delta Media Server,Delta-Media-Server,,1,true,"parent","[]","{}"

After powershell processes the whole CSV it ends up with something like this

[
    {
        "manufacturer":  "7th Sense",
        "model":  "Delta Media Server",
        "slug":  "Delta-Media-Server",
        "part_number":  "",
        "u_height":  "1",
        "is_full_depth":  "true",
        "subdevice_role":  "parent",
        "tags":  "[]",
        "comments":  "{}"
    },
    {
        "manufacturer":  "APC",
        "model":  "SMX1500RM2U",
        "slug":  "SMX1500RM2U",
        "part_number":  "",
        "u_height":  "1",
        "is_full_depth":  "true",
        "subdevice_role":  "",
        "tags":  "[]",
        "comments":  "{}"
    }
]

This of course requires some formatting and after that we are left with

[
    {
        "manufacturer":  "7th Sense",
        "model":  "Delta Media Server",
        "slug":  "Delta-Media-Server",
        "part_number":  "",
        "u_height":  1,
        "is_full_depth":  true,
        "subdevice_role":  "parent",
        "tags":  [],
        "comments":  {}
    },
    {
        "manufacturer":  "APC",
        "model":  "SMX1500RM2U",
        "slug":  "SMX1500RM2U",
        "part_number":  "",
        "u_height":  1,
        "is_full_depth":  true,
        "subdevice_role":  "parent",
        "tags":  [],
        "comments":  {}
    }
]

Trying to import this json data into the webapp still results in the above error. However, after visiting the nifty api, I can get another error.
image

This leads me to believe that I can not enter a string for the "manufacturer"'s field. I will have to continue diving into this and see if I can get anything more

@JustOneMoreDog commented on GitHub (Feb 26, 2020): I continued diving into this issue and I think the main issue is the "manufacturer" field. I went into the API and adjusted my fields based off of what was there ``` { "manufacturer": "7th Sense", "model": "Delta Media Server", "slug": "Delta-Media-Server", "part_number": "", "u_height": 1, "is_full_depth": true, "subdevice_role": "parent", "tags": [], "comments": {} } ``` This of course required more adjustments to my CSV ``` manufacturer,model,slug,part_number,u_height,is_full_depth,subdevice_role,tags,comments 7th Sense,Delta Media Server,Delta-Media-Server,,1,true,"parent","[]","{}" ``` After powershell processes the whole CSV it ends up with something like this ``` [ { "manufacturer": "7th Sense", "model": "Delta Media Server", "slug": "Delta-Media-Server", "part_number": "", "u_height": "1", "is_full_depth": "true", "subdevice_role": "parent", "tags": "[]", "comments": "{}" }, { "manufacturer": "APC", "model": "SMX1500RM2U", "slug": "SMX1500RM2U", "part_number": "", "u_height": "1", "is_full_depth": "true", "subdevice_role": "", "tags": "[]", "comments": "{}" } ] ``` This of course requires some formatting and after that we are left with ``` [ { "manufacturer": "7th Sense", "model": "Delta Media Server", "slug": "Delta-Media-Server", "part_number": "", "u_height": 1, "is_full_depth": true, "subdevice_role": "parent", "tags": [], "comments": {} }, { "manufacturer": "APC", "model": "SMX1500RM2U", "slug": "SMX1500RM2U", "part_number": "", "u_height": 1, "is_full_depth": true, "subdevice_role": "parent", "tags": [], "comments": {} } ] ``` Trying to import this json data into the webapp still results in the above error. However, after visiting the nifty api, I can get another error. ![image](https://user-images.githubusercontent.com/42121635/75374311-07f62080-589a-11ea-9d2b-784414362fa7.png) This leads me to believe that I can not enter a string for the "manufacturer"'s field. I will have to continue diving into this and see if I can get anything more
Author
Owner

@JustOneMoreDog commented on GitHub (Feb 26, 2020):

Alright I got this working. For those that come after me here is a checklist you need to go through to get this to work

  1. Use the API /api/docs/
  2. Use the POST /dcim/device-types/ to do the import
  3. Make sure you only use numbers, letters, underscores, and hyphens for your slug names ( I had some periods in mine causing errors ).
  4. Make sure you are not putting in duplicates.
  5. Make sure that you follow the docs and make your values the right type ( ie put 1 not "1" )
  6. Only use the fields that are required and that you need.

Here is an example of a correctly JSON entry

[
    {
        "manufacturer":  { "name": "7th Sense",  "slug": "7th-Sense"},
        "model":  "Delta Media Server",
        "slug":  "Delta-Media-Server",
        "u_height":  1
    },
    {
        "manufacturer":  { "name": "APC",  "slug": "APC"},
        "model":  "SMX2000RML2U",
        "slug":  "SMX2000RML2U",
        "u_height":  1
    },
    {
        "manufacturer":  { "name": "Extron",  "slug": "Extron"},
        "model":  "SSP 7.1",
        "slug":  "SSP-71",
        "u_height":  1
    }
]
@JustOneMoreDog commented on GitHub (Feb 26, 2020): Alright I got this working. For those that come after me here is a checklist you need to go through to get this to work 1) Use the API `/api/docs/` 2) Use the `POST` `/dcim/device-types/` to do the import 3) Make sure you only use numbers, letters, underscores, and hyphens for your slug names ( I had some periods in mine causing errors ). 4) Make sure you are not putting in duplicates. 5) Make sure that you follow the docs and make your values the right type ( ie put 1 not "1" ) 6) Only use the fields that are required and that you need. Here is an example of a correctly JSON entry ``` [ { "manufacturer": { "name": "7th Sense", "slug": "7th-Sense"}, "model": "Delta Media Server", "slug": "Delta-Media-Server", "u_height": 1 }, { "manufacturer": { "name": "APC", "slug": "APC"}, "model": "SMX2000RML2U", "slug": "SMX2000RML2U", "u_height": 1 }, { "manufacturer": { "name": "Extron", "slug": "Extron"}, "model": "SSP 7.1", "slug": "SSP-71", "u_height": 1 } ] ```
Author
Owner

@DanSheps commented on GitHub (Feb 27, 2020):

I am going to close this out, since this is not a bug or a feature request.

I will note, however, that I believe periods should work in slug names, even for imports.

@DanSheps commented on GitHub (Feb 27, 2020): I am going to close this out, since this is not a bug or a feature request. I will note, however, that I believe periods should work in slug names, even for imports.
Author
Owner

@JustOneMoreDog commented on GitHub (Feb 27, 2020):

Thank you for closing it out for me

@JustOneMoreDog commented on GitHub (Feb 27, 2020): Thank you for closing it out for me
Author
Owner

@stale[bot] commented on GitHub (Mar 11, 2020):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.

@stale[bot] commented on GitHub (Mar 11, 2020): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3417