I am following the guide on: https://github.com/microsoftgraph/msgraph-sdk-python to build a Python package that can pull all my devices from Azure AD (Entra). I have confirmed good working API credentials and that they have the right permissions:
My code is below
async def get_AADdevices():
MScredential = ClientSecretCredential(
tenant_id=os.environ['MSGraphTenantID'],
client_id=os.environ['MSGraphClientID'],
client_secret=os.environ['MSGraphClientSecret']
)
scopes = ['https://graph.microsoft.com/.default']
client = GraphServiceClient(credentials=MScredential, scopes=scopes)
devices = await client.devices.get()
I am getting the following error when it calls the await client.devices.get():
Executed 'Functions.MachineReconciliation' (Failed, Id=d6a7b205-25fc-4dfa-ad22-3621ed0b4144, Duration=9ms)
System.Private.CoreLib: Exception while executing function: Functions.MachineReconciliation. System.Private.CoreLib: Result: Failure
Exception: ValueError: not enough values to unpack (expected 2, got 1)
Stack: File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 479, in _handle__invocation_request
call_result = await self._loop.run_in_executor(
File "C:\Users\<user>\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 752, in _run_sync_func
return ExtensionManager.get_sync_invocation_wrapper(context,
File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10/WINDOWS/X64\azure_functions_worker\extension.py", line 215, in _raw_invocation_wrapper
result = function(**args)
File "C:\Users\<path>\function_app.py", line 17, in MachineReconciliation
asyncio.run(get_AADdevices())
File "C:\Users\<user>\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\<user>\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 649, in run_until_complete
return future.result()
File "C:\Users\<path>\function_app.py", line 40, in get_AADdevices
devices = await client.devices.get()
File "C:\Users\<path>\.venv\lib\site-packages\msgraph\generated\devices\devices_request_builder.py", line 70, in get
return await self.request_adapter.send_async(request_info, DeviceCollectionResponse, error_mapping)
File "C:\Users\<path>\.venv\lib\site-packages\kiota_http\httpx_request_adapter.py", line 162, in send_async
parent_span = self.start_tracing_span(request_info, "send_async")
File "C:\Users\<path>\.venv\lib\site-packages\kiota_http\httpx_request_adapter.py", line 131, in start_tracing_span
uri_template = ParametersNameDecodingHandler.decode_uri_encoded_string(
File "C:\Users\<path>\.venv\lib\site-packages\kiota_http\middleware\parameters_name_decoding_handler.py", line 92, in decode_uri_encoded_string
name, value = name_value.split('=')
Any ideas?
I am expecting it to return a list of devices