<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python import csv API in Network Platform API</title>
    <link>https://community.cisco.com/t5/network-platform-api/python-import-csv-api/m-p/5415416#M2765</link>
    <description>&lt;P&gt;The error message KeyError: 'portId' indicates that the key 'portId' is not found in the dictionary row.  The CSV file  does not have a column named 'portId'. You need to check the CSV and ensure that the column names match the keys you are using in your code.&lt;/P&gt;</description>
    <pubDate>Wed, 03 Apr 2024 14:47:30 GMT</pubDate>
    <dc:creator>aleabrahao</dc:creator>
    <dc:date>2024-04-03T14:47:30Z</dc:date>
    <item>
      <title>Python import csv API</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-import-csv-api/m-p/5415412#M2761</link>
      <description>&lt;P&gt;I am trying to import a csv of switch port configs.&lt;/P&gt;&lt;P&gt;I am able to print the csv from the below script&lt;/P&gt;&lt;PRE class="lia-code-sample language-python"&gt;&lt;CODE&gt;def read_csv_to_dict_list(filename):

data = []
with open(filename, 'r') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
data.append(row)
return data


data = read_csv_to_dict_list("C:\\temp\\Sample Switch.csv")

# Access data
for row in data:
print(f"Port: {row['portId']}, Name: {row['name']}, Tags: {row['tags']}, Type: {row['type']}, Vlan: {row['vlan']}, VoiceVlan: {row['voiceVlan']}")"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;how do I use this with  "updateDeviceSwitchPort"&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 20:40:32 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-import-csv-api/m-p/5415412#M2761</guid>
      <dc:creator>What In the</dc:creator>
      <dc:date>2024-04-02T20:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: Python import csv API</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-import-csv-api/m-p/5415413#M2762</link>
      <description>&lt;P&gt;Take a look on those links.&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/meraki/automation-scripts" target="_blank" rel="nofollow noopener noreferrer"&gt;https://github.com/meraki/automation-scripts&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/meraki/automation-scripts/blob/master/update_ports.py" target="_blank" rel="nofollow noopener noreferrer"&gt;https://github.com/meraki/automation-scripts/blob/master/update_ports.py&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 20:47:06 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-import-csv-api/m-p/5415413#M2762</guid>
      <dc:creator>aleabrahao</dc:creator>
      <dc:date>2024-04-02T20:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: Python import csv API</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-import-csv-api/m-p/5415414#M2763</link>
      <description>&lt;P&gt;You'll need to reference each field, individually.&lt;/P&gt;&lt;P&gt;Based on your print statement, something like&lt;/P&gt;&lt;PRE class="lia-code-sample language-python"&gt;&lt;CODE&gt;destSerial = 'Q2QN-9J8L-SLPD'

for row in data:
    response = dashboard.switch.updateDeviceSwitchPort(
        destSerial, row['portId'], 
        name=row['name'],
        tags=row['tags'],
        type=row['type'],
        vlan=row['vlan'], 
        voiceVlan=row['voiceVlan']
    )&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Apr 2024 05:50:44 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-import-csv-api/m-p/5415414#M2763</guid>
      <dc:creator>Rasmus Hoffmann Birkelund</dc:creator>
      <dc:date>2024-04-03T05:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: Python import csv API</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-import-csv-api/m-p/5415415#M2764</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;I get an error&lt;/P&gt;&lt;P&gt;line 41, in &amp;lt;module&amp;gt;&lt;BR /&gt;serial, Port=row["portId"],&lt;BR /&gt;~~~^^^^^^^^^^&lt;BR /&gt;KeyError: 'portId'&lt;/P&gt;&lt;P&gt;** I changed the serial line.  I have the SN as a variable already&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 14:37:38 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-import-csv-api/m-p/5415415#M2764</guid>
      <dc:creator>What In the</dc:creator>
      <dc:date>2024-04-03T14:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: Python import csv API</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-import-csv-api/m-p/5415416#M2765</link>
      <description>&lt;P&gt;The error message KeyError: 'portId' indicates that the key 'portId' is not found in the dictionary row.  The CSV file  does not have a column named 'portId'. You need to check the CSV and ensure that the column names match the keys you are using in your code.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 14:47:30 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-import-csv-api/m-p/5415416#M2765</guid>
      <dc:creator>aleabrahao</dc:creator>
      <dc:date>2024-04-03T14:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: Python import csv API</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-import-csv-api/m-p/5415417#M2766</link>
      <description>&lt;P&gt;line 1 of the csv is  Port,name,tags,type,vlan,voiceVlan&lt;/P&gt;&lt;P&gt;**Edit**  I updated the csv.  was getting confusing.&lt;/P&gt;&lt;P&gt;If I print the dictionary keys..&lt;/P&gt;&lt;P&gt;dict_keys(['Port_num', 'Port_name', 'Port_tag', 'Port_type', 'Port_vlan', 'Port_voiceVlan'])&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 14:53:32 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-import-csv-api/m-p/5415417#M2766</guid>
      <dc:creator>What In the</dc:creator>
      <dc:date>2024-04-03T14:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: Python import csv API</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-import-csv-api/m-p/5415418#M2767</link>
      <description>&lt;P&gt;I figured it out, kinda&lt;/P&gt;&lt;P&gt;I had the dict keys swapped with the update switch API requirements&lt;BR /&gt;&lt;BR /&gt;response = dashboard.switch.updateDeviceSwitchPort(&lt;BR /&gt;Serial, portId=row['Port_num'],&lt;BR /&gt;name=row['Port_name'],&lt;BR /&gt;type=row['Port_type'],&lt;BR /&gt;vlan=row['Port_vlan'],&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I removed tags as it wants an array, and voiceVlan as it must be an integer or null&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 15:37:34 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-import-csv-api/m-p/5415418#M2767</guid>
      <dc:creator>What In the</dc:creator>
      <dc:date>2024-04-03T15:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: Python import csv API</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-import-csv-api/m-p/5415419#M2768</link>
      <description>&lt;P&gt;!!UPDATE!!&lt;/P&gt;&lt;P&gt;I got it to work.&lt;/P&gt;&lt;P&gt;I added an if statement to replace empty cells with None&lt;/P&gt;&lt;PRE class="lia-code-sample language-python"&gt;&lt;CODE&gt;def read_csv_to_dict_list(filename):
data = []
with open(filename, 'r') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row['Port_voiceVlan'] == '':
row['Port_voiceVlan'] = None
data.append(row)
return data&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Apr 2024 18:28:18 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-import-csv-api/m-p/5415419#M2768</guid>
      <dc:creator>What In the</dc:creator>
      <dc:date>2024-04-04T18:28:18Z</dc:date>
    </item>
  </channel>
</rss>

