<?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 Meraki API library retries fail in Network Platform API</title>
    <link>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410912#M1941</link>
    <description>&lt;P&gt;Try to increase the timeout from 5s to 60s. You may have a large number of orgs which take longer than 5s to returns. &lt;/P&gt;</description>
    <pubDate>Thu, 07 Mar 2024 11:57:15 GMT</pubDate>
    <dc:creator>dajirku</dc:creator>
    <dc:date>2024-03-07T11:57:15Z</dc:date>
    <item>
      <title>Python Meraki API library retries fail</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410911#M1940</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;we need to maintain some automation in the form of an AWS Lambda function calling the Meraki dashboard API and updating our VPC routing tables accordingly&lt;/P&gt;&lt;P&gt;The problem we ran into was that every now and then we would get a 60 second timeout and the function would fail.&lt;/P&gt;&lt;P&gt;To solve this problem, we moved from the default API endpoint to our segment's FQDN (as suggested &lt;A href="https://community.meraki.com/t5/Developers-APIs/Meraki-API-timeout-after-120-seconds/m-p/130458" target="_self"&gt;here&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;Unfortunately, this did not solve the problem and the next step was to introduce timeouts and retries to call the Meraki API. The code looks like the following&lt;/P&gt;&lt;P&gt;initialising the Dashboard&lt;/P&gt;&lt;PRE class="lia-code-sample language-markup"&gt;&lt;CODE&gt;    meraki_base_url = MERAKI_BASE_URL
    logging.info (f'Meraki base URL: {meraki_base_url}')
    meraki_dashboard = meraki.DashboardAPI(base_url=meraki_base_url, api_key=meraki_api_key, suppress_logging=True, single_request_timeout=5, maximum_retries=3)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;calling it&lt;/P&gt;&lt;PRE class="lia-code-sample language-markup"&gt;&lt;CODE&gt;def get_meraki_tagged_networks(dashboard, org_id, vmx_tag):
    """
    Returns Meraki network IDs for the given organisation. 
    """

    logging.info('Executing API call to obtain all Meraki networks in the organization')
    try:
        organization_networks_response = dashboard.organizations.getOrganizationNetworks(
            org_id, total_pages='all'
        )
        vmx_network = [x for x in organization_networks_response if str(vmx_tag) in str(x['tags'])[1:-1]]
    except Exception as e:
        logging.error(f'Unknown error happened while retriving Meraki network IDs: {e}')
        sys.exit(1)

    if len(vmx_network) == 0:
        return None
    else:
        return vmx_network[0]['id']&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Unfortunately, the problem is still there and error we receive now is as follows&lt;/P&gt;&lt;PRE class="lia-code-sample language-markup"&gt;&lt;CODE&gt;[INFO]	2024-03-05T23:01:18.698Z	0565e7a3-f0a3-4df6-8db3-25e4e3952a68	Executing API call to obtain all Meraki networks in the organization
[ERROR]	2024-03-05T23:01:23.306Z	0565e7a3-f0a3-4df6-8db3-25e4e3952a68	Unknown error happened while retriving Meraki network IDs: organizations, getOrganizationNetworks - 502 Bad Gateway, &amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;502 Bad Gateway&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;center&amp;gt;&amp;lt;h1&amp;gt;502 Bad Gateway&amp;lt;/h1&amp;gt;&amp;lt;/cente&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So it seems that the retries number is not respected, otherwise time between log records would have been 15 second(3 multiple by 5)&lt;/P&gt;&lt;P&gt;Any hint of what might be wrong?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2024 10:31:37 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410911#M1940</guid>
      <dc:creator>Nikita19</dc:creator>
      <dc:date>2024-03-07T10:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: Python Meraki API library retries fail</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410912#M1941</link>
      <description>&lt;P&gt;Try to increase the timeout from 5s to 60s. You may have a large number of orgs which take longer than 5s to returns. &lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2024 11:57:15 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410912#M1941</guid>
      <dc:creator>dajirku</dc:creator>
      <dc:date>2024-03-07T11:57:15Z</dc:date>
    </item>
    <item>
      <title>Re: Python Meraki API library retries fail</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410913#M1942</link>
      <description>&lt;P&gt;Thank you for the advice &lt;SPAN class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt; &lt;BR /&gt;However, it's still testing installation with very small number of data, so pulling data should not take long...&lt;BR /&gt;The question is more - why it didn't retry on calling the API when first request failed?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2024 12:00:40 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410913#M1942</guid>
      <dc:creator>Nikita19</dc:creator>
      <dc:date>2024-03-07T12:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: Python Meraki API library retries fail</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410914#M1943</link>
      <description>&lt;P&gt;Try removing the base_url from the object instantiation? I.e.&lt;/P&gt;&lt;PRE class="lia-code-sample language-python"&gt;&lt;CODE&gt;meraki_api_key = "xxxx"
logging.info (f'Meraki base URL: {meraki_base_url}')
meraki_dashboard = meraki.DashboardAPI(meraki_api_key, 
    suppress_logging=True, 
    single_request_timeout=5, 
    maximum_retries=3
)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Mar 2024 13:01:39 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410914#M1943</guid>
      <dc:creator>Rasmus Hoffmann Birkelund</dc:creator>
      <dc:date>2024-03-07T13:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: Python Meraki API library retries fail</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410915#M1944</link>
      <description>&lt;P&gt;Also make sure you are using the latest version of the Meraki SDK.&lt;/P&gt;&lt;PRE class="lia-code-sample language-python"&gt;&lt;CODE&gt;pip install --upgrade meraki&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Mar 2024 13:02:37 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410915#M1944</guid>
      <dc:creator>Rasmus Hoffmann Birkelund</dc:creator>
      <dc:date>2024-03-07T13:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: Python Meraki API library retries fail</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410916#M1945</link>
      <description>&lt;P&gt;we're on 1.42.0, almost the latest one&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2024 13:27:12 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410916#M1945</guid>
      <dc:creator>Nikita19</dc:creator>
      <dc:date>2024-03-07T13:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: Python Meraki API library retries fail</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410917#M1946</link>
      <description>&lt;P&gt;Thank you &lt;/P&gt;&lt;P&gt;I'll anyway move back to the default API, but why do you think it will work out?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2024 13:27:40 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410917#M1946</guid>
      <dc:creator>Nikita19</dc:creator>
      <dc:date>2024-03-07T13:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: Python Meraki API library retries fail</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410918#M1947</link>
      <description>&lt;P&gt;Could you do a test for me; if you take the Meraki component of the code and run it locally on your machine in a loop - do you see the same issue happening?&lt;/P&gt;&lt;P&gt;I'm more used to using the asyncio version of the library, but try these two parameters:&lt;/P&gt;&lt;P&gt;maximum_retries=100,&lt;BR /&gt;wait_on_rate_limit=True&lt;/P&gt;&lt;P&gt;You can find all the parameters here:&lt;BR /&gt;&lt;A href="https://github.com/meraki/dashboard-api-python/blob/243922d006d158759311b94183f4a40eebb1ac3e/meraki/__init__.py#L49" target="_self" rel="nofollow noopener noreferrer"&gt;https://github.com/meraki/dashboard-api-python/blob/243922d006d158759311b94183f4a40eebb1ac3e/meraki/__init__.py#L49&lt;/A&gt; &lt;/P&gt;&lt;P&gt;And these are the default parameters:&lt;BR /&gt;&lt;A href="https://github.com/meraki/dashboard-api-python/blob/main/meraki/config.py" target="_self" rel="nofollow noopener noreferrer"&gt;https://github.com/meraki/dashboard-api-python/blob/main/meraki/config.py&lt;/A&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2024 19:43:54 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410918#M1947</guid>
      <dc:creator>Philip D'Ath</dc:creator>
      <dc:date>2024-03-07T19:43:54Z</dc:date>
    </item>
    <item>
      <title>Re: Python Meraki API library retries fail</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410919#M1948</link>
      <description>&lt;P&gt;The main Meraki Python library retry mechanism is explicitly for handling the 429 response used by the API to signal the rate limit has been hit (there're also some other retry mechanisms for a few specific 4xx error contexts).&lt;/P&gt;&lt;P&gt;Your example shows a 502 bad gateway response, there will be no retry, it is a hard error.&lt;/P&gt;&lt;P&gt;If you want to retry on 502, you'll need to add your own code to do that, but as 502 errors may last a while I would recommend a fairly long interval before trying again.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2024 20:31:04 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410919#M1948</guid>
      <dc:creator>sungod</dc:creator>
      <dc:date>2024-03-07T20:31:04Z</dc:date>
    </item>
    <item>
      <title>Re: Python Meraki API library retries fail</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410920#M1949</link>
      <description>&lt;P&gt;The library will retry 5XX errors every 1 second until the number of retries specified is exhausted. Exponential backoff would likely be better, but there is -something-&lt;/P&gt;&lt;PRE class="lia-code-sample language-python"&gt;&lt;CODE&gt;# 5XX errors
elif status &amp;gt;= 500:
    if self._logger:
        self._logger.warning(f'{tag}, {operation} - {status} {reason}, retrying in 1 second')
    time.sleep(1)
    retries -= 1
    if retries == 0:
        raise APIError(metadata, response)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Mar 2024 21:04:32 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410920#M1949</guid>
      <dc:creator>matt_uc</dc:creator>
      <dc:date>2024-03-07T21:04:32Z</dc:date>
    </item>
    <item>
      <title>Re: Python Meraki API library retries fail</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410921#M1950</link>
      <description>&lt;P&gt;Ah, I must be going blind, I missed that when I looked at the code!&lt;/P&gt;&lt;P&gt;A 1 second retry on 5xx responses seems hopeful at best &lt;SPAN class="lia-unicode-emoji" title=":grinning_face:"&gt;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Mar 2024 08:51:04 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410921#M1950</guid>
      <dc:creator>sungod</dc:creator>
      <dc:date>2024-03-08T08:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: Python Meraki API library retries fail</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410922#M1951</link>
      <description>&lt;P&gt;than, the documentation is misleading as it described this parameter as &lt;/P&gt;&lt;P&gt;"retry up to this many times when encountering 429s or other server-side errors"&lt;/P&gt;&lt;P&gt;and the 502 error is server side one...&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2024 08:47:15 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410922#M1951</guid>
      <dc:creator>Nikita19</dc:creator>
      <dc:date>2024-03-11T08:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: Python Meraki API library retries fail</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410923#M1952</link>
      <description>&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;I'm testing the &lt;A href="https://pypi.org/project/retry/" target="_self" rel="nofollow noopener noreferrer"&gt;retry decorator&lt;/A&gt;,  will try it out if the decorator doesn't work&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2024 08:48:27 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-meraki-api-library-retries-fail/m-p/5410923#M1952</guid>
      <dc:creator>Nikita19</dc:creator>
      <dc:date>2024-03-11T08:48:27Z</dc:date>
    </item>
  </channel>
</rss>

