Git Product home page Git Product logo

Comments (6)

ollipa avatar ollipa commented on August 20, 2024

@TKIPisalegacycipher, seems that this was caused by this commit: 6d9ada0

message_is_dict is used in aio/rest_session but it is never set. In sync code (rest_session) this variable is set as follows but this code block is missing from aio/rest_session:

try:
    message = response.json()
    message_is_dict = True
except ValueError:
    message = response.content[:100]
    message_is_dict = False

from dashboard-api-python.

TKIPisalegacycipher avatar TKIPisalegacycipher commented on August 20, 2024

Hi @dpnetca are you still running into this issue? I've added debug logging here, so if so can you please provide the full debug log on the latest version of the library? Feel free to redact IDs and serial numbers.

from dashboard-api-python.

dpnetca avatar dpnetca commented on August 20, 2024

yes, tested with 1.36.0, 1.37.1 and 1.37.2 and I still get errors, though it looks like it may be slightly different with 3.17.x from 3.16.x

$ pip list | grep meraki
meraki             1.37.2

traceback:

$ python main.py admin.add

Traceback (most recent call last):
  File "/home/xxxxxx/code/py/work/momapy_cli/main.py", line 22, in <module>
    asyncio.run(admin_add())
  File "/home/xxxxxx/.pyenv/versions/3.11.4/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/home/xxxxxx/.pyenv/versions/3.11.4/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xxxxxx/.pyenv/versions/3.11.4/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/xxxxxx/code/py/work/momapy_cli/admin/add.py", line 91, in admin_add
    results = [await task async for task in tqdm_tasks]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xxxxxx/code/py/work/momapy_cli/admin/add.py", line 91, in <listcomp>
    results = [await task async for task in tqdm_tasks]
               ^^^^^^^^^^
  File "/home/xxxxxx/.pyenv/versions/3.11.4/lib/python3.11/asyncio/tasks.py", line 605, in _wait_for_one
    return f.result()  # May raise f.exception().
           ^^^^^^^^^^
  File "/home/xxxxxx/code/py/work/momapy_cli/admin/add.py", line 29, in add_org_admin
    add_result = await dashboard.organizations.createOrganizationAdmin(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xxxxxx/code/py/work/momapy_cli/.venv/lib/python3.11/site-packages/meraki/aio/rest_session.py", line 505, in post
    async with await self.request(metadata, "POST", url, json=json) as response:
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xxxxxx/code/py/work/momapy_cli/.venv/lib/python3.11/site-packages/meraki/aio/rest_session.py", line 134, in request
    return await self._request(
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/xxxxxx/code/py/work/momapy_cli/.venv/lib/python3.11/site-packages/meraki/aio/rest_session.py", line 273, in _request
    if message_is_dict and 'errors' in message.keys() \
       ^^^^^^^^^^^^^^^
NameError: name 'message_is_dict' is not defined

from dashboard-api-python.

dpnetca avatar dpnetca commented on August 20, 2024

@TKIPisalegacycipher
Difference seems to be here, in the sync rest_session code for 4xx errors the message_is_dict is being initialized to either true or false

                    try:
                        message = response.json()
                        message_is_dict = True
                    except ValueError:
                        message = response.content[:100]
                        message_is_dict = False

However, in the equivalent section in the aio library the message_is_dict is not initialized

                    try:
                        message = await response.json(content_type = None)
                    except aiohttp.client_exceptions.ContentTypeError:
                        logging.debug(f"message is {message}")
                        logging.debug(f"message is dict? {isinstance(message, dict)}")
                        try:
                            message = (await response.text())[:100]
                            logging.debug(f"message is {message}")
                            logging.debug(f"message is dict? {isinstance(message, dict)}")
                        except:
                            message = None

manually editing my local copy of tat file to the following and code executes without error:

                    try:
                        message = await response.json(content_type=None)
                        message_is_dict = True
                        ...

from dashboard-api-python.

dpnetca avatar dpnetca commented on August 20, 2024

Sorry for the multiple messages, but one more thing of note. looking back at at the 1.36.0 code before the debug was added I can see message_is_dict was initiated here partially, but missing a few things ( see my added comments) the issue is if the first TRY succeeds (which in my case it is) then message_is_dict is not initialized. causing the error. if the first fails and hits the exception, then it is set incorrectly in the second try, in this case it would be a string not a dict but that is still set to True should be False:

                # 4XX errors
                else:
                    try:
                        message = await response.json(content_type = None)
                        # message_is_dict = True should be set here
                    except aiohttp.client_exceptions.ContentTypeError:
                        try:
                            message = (await response.text())[:100]
                            message_is_dict = True   # this should be False not True
                        except:
                            message = None
                            message_is_dict = False

from dashboard-api-python.

dpnetca avatar dpnetca commented on August 20, 2024

quick test and it looks like the issue is resolved with 1.37.3. thank you!!

from dashboard-api-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.