Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid key: OAuthConsentGrant for enum #454

Closed
Babyhamsta opened this issue Nov 10, 2023 · 3 comments
Closed

Invalid key: OAuthConsentGrant for enum #454

Babyhamsta opened this issue Nov 10, 2023 · 3 comments
Assignees
Labels
Status: No Recent Activity status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close

Comments

@Babyhamsta
Copy link

I am getting an error when I attempt to just use the bare requests for all attack simulations. Nothing special just sending a single request to get all simulations and I get this error: Invalid key: OAuthConsentGrant for enum.

Error:

Client has logged in successfully
Traceback (most recent call last):
  File "C:\Users\username\Desktop\MSGraph\.venv\Lib\site-packages\kiota_serialization_json\json_parse_node.py", line 199, in get_enum_value
    return enum_class[camel_case_key]  # type: ignore
           ~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "c:\Program Files\Python311\Lib\enum.py", line 790, in __getitem__
    return cls._member_map_[name]
           ~~~~~~~~~~~~~~~~^^^^^^
KeyError: 'OAuthConsentGrant'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\username\Desktop\MSGraph\main.py", line 22, in <module>
    loop.run_until_complete(main())
  File "c:\Program Files\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\username\Desktop\MSGraph\main.py", line 17, in main
    simulations = await ListSimulations()
                  ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Desktop\MSGraph\main.py", line 10, in ListSimulations
    results = await client.security.attack_simulation.simulations.get()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Desktop\MSGraph\.venv\Lib\site-packages\msgraph\generated\security\attack_simulation\simulations\simulations_request_builder.py", line 66, in get
    return await self.request_adapter.send_async(request_info, SimulationCollectionResponse, error_mapping)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Desktop\MSGraph\.venv\Lib\site-packages\kiota_http\httpx_request_adapter.py", line 181, in send_async
    value = root_node.get_object_value(parsable_factory)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Desktop\MSGraph\.venv\Lib\site-packages\kiota_serialization_json\json_parse_node.py", line 212, in get_object_value
    self._assign_field_values(result)
  File "C:\Users\username\Desktop\MSGraph\.venv\Lib\site-packages\kiota_serialization_json\json_parse_node.py", line 281, in _assign_field_values
    field_deserializer(JsonParseNode(field_value))
  File "C:\Users\username\Desktop\MSGraph\.venv\Lib\site-packages\msgraph\generated\models\simulation_collection_response.py", line 40, in <lambda>
    "value": lambda n : setattr(self, 'value', n.get_collection_of_object_values(Simulation)),
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Desktop\MSGraph\.venv\Lib\site-packages\kiota_serialization_json\json_parse_node.py", line 163, in get_collection_of_object_values
    return list(
           ^^^^^
  File "C:\Users\username\Desktop\MSGraph\.venv\Lib\site-packages\kiota_serialization_json\json_parse_node.py", line 165, in <lambda>
    lambda x: self._create_new_node(x).get_object_value(factory),  # type: ignore
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Desktop\MSGraph\.venv\Lib\site-packages\kiota_serialization_json\json_parse_node.py", line 212, in get_object_value
    self._assign_field_values(result)
  File "C:\Users\username\Desktop\MSGraph\.venv\Lib\site-packages\kiota_serialization_json\json_parse_node.py", line 281, in _assign_field_values
    field_deserializer(JsonParseNode(field_value))
  File "C:\Users\username\Desktop\MSGraph\.venv\Lib\site-packages\msgraph\generated\models\simulation.py", line 125, in <lambda>
    "attackTechnique": lambda n : setattr(self, 'attack_technique', n.get_enum_value(SimulationAttackTechnique)),
                                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Desktop\MSGraph\.venv\Lib\site-packages\kiota_serialization_json\json_parse_node.py", line 201, in get_enum_value
    raise Exception(f'Invalid key: {camel_case_key} for enum {enum_class}.')
Exception: Invalid key: OAuthConsentGrant for enum <enum 'SimulationAttackTechnique'>.

Example Code:

import asyncio, os
from utils.GraphTokenHandler import TokenHandler

client = TokenHandler.GetClient()

# Pull simulations from Attack Simulations via client
async def ListSimulations():
    results = await client.security.attack_simulation.simulations.get()
    return results

async def main():
    if client:
        print("Client has logged in successfully")
    simulations = await ListSimulations()
    #print(simulations)
    
if __name__ ==  '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())
@andrueastman
Copy link
Member

Possibly related to work at microsoft/kiota-serialization-json-python#265

@shemogumbe
Copy link
Collaborator

Hello @Babyhamsta @andrueastman this is indeed related to microsoft/kiota-serialization-json-python#265 and is fixed:

@Babyhamsta could you try it with the updated version of the serialization library or latest version of the SDK?

@shemogumbe shemogumbe added the status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close label Aug 27, 2024

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: No Recent Activity status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close
Projects
None yet
Development

No branches or pull requests

3 participants