<?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: How to Bypass  or Continue netapp_ontap.error.NetAppRestError:  Python in Python Discussions</title>
    <link>https://community.netapp.com/t5/Python-Discussions/How-to-Bypass-or-Continue-netapp-ontap-error-NetAppRestError-Python/m-p/166642#M56</link>
    <description>&lt;P&gt;The&amp;nbsp;&lt;SPAN&gt;NetAppRestError object is the standard exception that might be raised from the library whenever the server provides an error response to the client. An error response is any API request that returns a status code of &amp;gt;= 400. If you want your application to continue, you should handle the exception like any other in Python with a try/except block wrapped around the block of code that might throw an exception you want to handle.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here is your code with a try/except that reports the error but keeps going:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;from netapp_ontap import HostConnection, NetAppRestError
from netapp_ontap.resources import Volume, Snapshot

with HostConnection(hostname, username, password, verify=False):
    vols = Volume.get_collection()

    for volx in vols :
        volx.get(fields='uuid,svm,name')
        vservername = volx.svm.name
        print(volx.svm.name)
        snaps = Snapshot.get_collection(volx.uuid)
            for snapx in snaps :
            print(volx.name)
            try:
                snapx.get(fields='volume,snapmirror_label,create_time,name')
            except NetAppRestError as e:
                print("Error fetching snapshot details: %s" % e)&lt;/LI-CODE&gt;&lt;P&gt;On a side note, your code could be made a little more efficient. Right now, you are calling get_collection() and then for each result you are calling get() on it inside the loop to fetch additional fields. You could make this more efficient by passing the field list to get_collection() and then you don't need the get() inside. Here is the same code refactored:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;from netapp_ontap import HostConnection, NetAppRestError
from netapp_ontap.resources import Volume, Snapshot

with HostConnection(hostname, username, password, verify=False):
    for volx in Volume.get_collection(fields="uuid,svm,name"):
        vservername = volx.svm.name
        print(volx.svm.name)
        for snapx in Snapshot.get_collection(volx.uuid, fields="volume,snapmirror_label,create_time,name")
            print(snapx.name)&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 07 May 2021 10:23:13 GMT</pubDate>
    <dc:creator>RobertBlackhart</dc:creator>
    <dc:date>2021-05-07T10:23:13Z</dc:date>
    <item>
      <title>How to Bypass  or Continue netapp_ontap.error.NetAppRestError:  Python</title>
      <link>https://community.netapp.com/t5/Python-Discussions/How-to-Bypass-or-Continue-netapp-ontap-error-NetAppRestError-Python/m-p/166430#M53</link>
      <description>&lt;DIV&gt;&lt;P&gt;Smart people of Netapp API I am trying to collect individual snapshot name and information to see whether a snapmirror was created on it or not&lt;/P&gt;&lt;P&gt;In the process I get volume information and use uuid to fetch snapshot for each volume somewhere it gets stuck and I see this 404 error &amp;nbsp;&lt;/P&gt;&lt;P&gt;Once I get the error for a particular volume/snapshot like below&amp;nbsp; it Breaks the&amp;nbsp; loop and exits. I understand it that there is some issue with some object&amp;nbsp; but I want to catch this and bypass the error to next volume or volume-snapshot&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;with HostConnection(hostname, username, password, verify=False):&lt;BR /&gt;vols = Volume.get_collection()&lt;/P&gt;&lt;P&gt;for volx in vols :&lt;BR /&gt;volx.get(fields='uuid,svm,name')&lt;BR /&gt;vservername = volx.svm.name&lt;BR /&gt;print(volx.svm.name)&lt;BR /&gt;snaps = Snapshot.get_collection(volx.uuid)&lt;BR /&gt;for snapx in snaps :&lt;BR /&gt;print(volx.name)&lt;BR /&gt;snapx.get(fields='volume,snapmirror_label,create_time,name')&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I get the following&lt;/P&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;netapp_ontap.error.NetAppRestError: Caused by HTTPError('404 Client Error: Not Found for url: &lt;A href="https://192.168.xx.xx:443/api/storage/volumes/0090909090909yyhgg00hgv/snapshots0090909090909yyhgg00hgv?fields=volume%2Csnapmirror_label%2Ccreate_time%2Cname%27" target="_blank" rel="noopener nofollow noreferrer"&gt;https://192.168.xx.xx:443/api/storage/volumes/0090909090909yyhgg00hgv/snapshots0090909090909yyhgg00hgv?fields=volume%2Csnapmirror_label%2Ccreate_time%2Cname'&lt;/A&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; entry doesn't exist&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;how to catch this is error in a variable&amp;nbsp; .. its generated by snapx.get(fields='volume,snapmirror_label,create_time,name') iteration and I want to "continue" and not "break"&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Hope I explained properly&lt;/DIV&gt;</description>
      <pubDate>Wed, 04 Jun 2025 10:26:25 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Python-Discussions/How-to-Bypass-or-Continue-netapp-ontap-error-NetAppRestError-Python/m-p/166430#M53</guid>
      <dc:creator>a4ashu</dc:creator>
      <dc:date>2025-06-04T10:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to Bypass  or Continue netapp_ontap.error.NetAppRestError:  Python</title>
      <link>https://community.netapp.com/t5/Python-Discussions/How-to-Bypass-or-Continue-netapp-ontap-error-NetAppRestError-Python/m-p/166642#M56</link>
      <description>&lt;P&gt;The&amp;nbsp;&lt;SPAN&gt;NetAppRestError object is the standard exception that might be raised from the library whenever the server provides an error response to the client. An error response is any API request that returns a status code of &amp;gt;= 400. If you want your application to continue, you should handle the exception like any other in Python with a try/except block wrapped around the block of code that might throw an exception you want to handle.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here is your code with a try/except that reports the error but keeps going:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;from netapp_ontap import HostConnection, NetAppRestError
from netapp_ontap.resources import Volume, Snapshot

with HostConnection(hostname, username, password, verify=False):
    vols = Volume.get_collection()

    for volx in vols :
        volx.get(fields='uuid,svm,name')
        vservername = volx.svm.name
        print(volx.svm.name)
        snaps = Snapshot.get_collection(volx.uuid)
            for snapx in snaps :
            print(volx.name)
            try:
                snapx.get(fields='volume,snapmirror_label,create_time,name')
            except NetAppRestError as e:
                print("Error fetching snapshot details: %s" % e)&lt;/LI-CODE&gt;&lt;P&gt;On a side note, your code could be made a little more efficient. Right now, you are calling get_collection() and then for each result you are calling get() on it inside the loop to fetch additional fields. You could make this more efficient by passing the field list to get_collection() and then you don't need the get() inside. Here is the same code refactored:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;from netapp_ontap import HostConnection, NetAppRestError
from netapp_ontap.resources import Volume, Snapshot

with HostConnection(hostname, username, password, verify=False):
    for volx in Volume.get_collection(fields="uuid,svm,name"):
        vservername = volx.svm.name
        print(volx.svm.name)
        for snapx in Snapshot.get_collection(volx.uuid, fields="volume,snapmirror_label,create_time,name")
            print(snapx.name)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 07 May 2021 10:23:13 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Python-Discussions/How-to-Bypass-or-Continue-netapp-ontap-error-NetAppRestError-Python/m-p/166642#M56</guid>
      <dc:creator>RobertBlackhart</dc:creator>
      <dc:date>2021-05-07T10:23:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to Bypass  or Continue netapp_ontap.error.NetAppRestError:  Python</title>
      <link>https://community.netapp.com/t5/Python-Discussions/How-to-Bypass-or-Continue-netapp-ontap-error-NetAppRestError-Python/m-p/166652#M57</link>
      <description>&lt;P&gt;Thank you Robert for your elaborate response I think this is what I was looking for . I realized quickly that I was little lazy coding ( first time ever in my life) there when I seperated the get() and get_collection. To any readers of this message please use the what Robert has asked it works .&lt;/P&gt;&lt;P&gt;The second thing I want to point out is how your blog on {getattr(snapx, 'snapmirror_label', 'not set')} helped , so just for everyone reading this blog there are cases where the variable is not set , leaving code in lurch. Robert gave a nice workaround of using getattr and setting it to some default specified value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if any(str1 in snapx.name for str1 in snapmirrorsnapshot1) : #any(x in str for x in myList to identify )&lt;BR /&gt;print("\n")&lt;BR /&gt;print(snapx.volume.name,volx.uuid,snapx.name ,snapx.create_time,{getattr(snapx, 'snapmirror_label', 'snapmirror not set')} )&lt;/P&gt;&lt;P&gt;&amp;lt;— helped me bypass&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As far as the exceptions are .. they do not always show up , in some cases sometimes and hence not replicable but I have added try and except to the code hopefully that might mitigate the break. I will keep testing till it breaks and hopefully this would be the final solution .&lt;/P&gt;</description>
      <pubDate>Fri, 07 May 2021 15:14:54 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Python-Discussions/How-to-Bypass-or-Continue-netapp-ontap-error-NetAppRestError-Python/m-p/166652#M57</guid>
      <dc:creator>a4ashu</dc:creator>
      <dc:date>2021-05-07T15:14:54Z</dc:date>
    </item>
  </channel>
</rss>

