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

Object has no attribute 'get_all' when calling calendar.get_schedule.post() #451

Open
hiitsmax opened this issue Nov 9, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@hiitsmax
Copy link

hiitsmax commented Nov 9, 2023

I'm currently trying to get a room schedule through this code:

credential = ClientSecretCredential(
    config['tenantID'],
    config['clientID'],
    config['clientSecret']
)
scopes = ['https://graph.microsoft.com/.default']
client = GraphServiceClient(credentials=credential, scopes=scopes)

# GET /users/{id | userPrincipalName}
async def get_rooms():
    
    request_body = GetSchedulePostRequestBody(
        schedules = [
            "StanzaA@qq7h.onmicrosoft.com"
        ],
        start_time = DateTimeTimeZone(
            date_time = "2023-03-15T09:00:00",
            time_zone = "Pacific Standard Time",
        ),
        end_time = DateTimeTimeZone(
            date_time = "2023-12-15T18:00:00",
            time_zone = "Pacific Standard Time",
        ),
        availability_view_interval = 60,
    )

    request_configuration = GetScheduleRequestBuilder.GetScheduleRequestBuilderPostRequestConfiguration(
    headers = {
            'Prefer' : "outlook.timezone=\"Pacific Standard Time\"",
    }

    )

    result = await client.me.calendar.get_schedule.post(request_body, request_configuration = request_configuration)


    if result:
        print(result.value)

asyncio.run(get_rooms())

But when running I get an error coming from kiota

Traceback (most recent call last):
  File "C:\Users\Massimo Mendozza\Documents\GitHub\DynamicsToJoan\main.py", line 52, in <module>
    asyncio.run(get_rooms())
  File "C:\Users\Massimo Mendozza\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\Massimo Mendozza\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Massimo Mendozza\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 650, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\Massimo Mendozza\Documents\GitHub\DynamicsToJoan\main.py", line 46, in get_rooms
    result = await client.me.calendar.get_schedule.post(request_body, request_configuration = request_configuration)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Massimo Mendozza\Documents\GitHub\DynamicsToJoan\Lib\site-packages\msgraph\generated\users\item\calendar\get_schedule\get_schedule_request_builder.py", line 40, in post
    request_info = self.to_post_request_information(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Massimo Mendozza\Documents\GitHub\DynamicsToJoan\Lib\site-packages\msgraph\generated\users\item\calendar\get_schedule\get_schedule_request_builder.py", line 66, in to_post_request_information        
    request_info.headers.add_all(request_configuration.headers)
  File "C:\Users\Massimo Mendozza\Documents\GitHub\DynamicsToJoan\Lib\site-packages\kiota_abstractions\headers_collection.py", line 83, in add_all
    for key, values in headers.get_all().items():
                       ^^^^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'get_all'

I'm currently running under this pyvenv:

home = C:\Users\Massimo Mendozza\AppData\Local\Programs\Python\Python311
include-system-site-packages = false
version = 3.11.0
executable = C:\Users\Massimo Mendozza\AppData\Local\Programs\Python\Python311\python.exe
command = C:\Users\Massimo Mendozza\AppData\Local\Programs\Python\Python311\python.exe -m venv C:\Users\Massimo Mendozza\Documents\GitHub\DynamicsToJoan

And this are my packages version:

Package                              Version
------------------------------------ ---------
aiohttp                              3.8.6
aiosignal                            1.3.1
anyio                                4.0.0
async-timeout                        4.0.3
attrs                                23.1.0
azure-core                           1.29.5
azure-identity                       1.15.0
certifi                              2023.7.22
cffi                                 1.16.0
charset-normalizer                   3.3.2
cryptography                         41.0.5
Deprecated                           1.2.14
frozenlist                           1.4.0
h11                                  0.14.0
h2                                   4.1.0
hpack                                4.0.0
httpcore                             0.18.0
httpx                                0.25.0
hyperframe                           6.0.1
idna                                 3.4
importlib-metadata                   6.8.0
microsoft-kiota-abstractions         1.0.0
microsoft-kiota-authentication-azure 1.0.0
microsoft-kiota-http                 1.0.0
microsoft-kiota-serialization-json   1.0.0
microsoft-kiota-serialization-text   1.0.0
msal                                 1.24.1
msal-extensions                      1.0.0
msgraph-core                         1.0.0a4
msgraph-sdk                          1.0.0
multidict                            6.0.4
opentelemetry-api                    1.20.0
opentelemetry-sdk                    1.20.0
opentelemetry-semantic-conventions   0.41b0
pendulum                             2.1.2
pip                                  22.3
portalocker                          2.8.2
pycparser                            2.21
PyJWT                                2.8.0
python-dateutil                      2.8.2
python-dotenv                        1.0.0
pytzdata                             2020.1
pywin32                              306
requests                             2.31.0
setuptools                           65.5.0
six                                  1.16.0
sniffio                              1.3.0
std-uritemplate                      0.0.46
typing_extensions                    4.8.0
urllib3                              2.0.7
wrapt                                1.15.0
yarl                                 1.9.2
zipp                                 3.17.0
@pablorodriper
Copy link

Same issue with this example when I try to modify the header in MessageItemRequestBuilder.MessageItemRequestBuilderGetRequestConfiguration()

https://learn.microsoft.com/es-es/graph/api/message-get?view=graph-rest-1.0&tabs=python#example-3-get-message-body-in-text-format

@shemogumbe shemogumbe self-assigned this Nov 16, 2023
@A360-Paul
Copy link

A360-Paul commented Nov 22, 2023

This was a problem for me as well posting updates to Tasks, example code here.

I investigated and it appears there is a new class that contains the headers now "HeadersCollection", this is used by the base class "BaseRequestConfiguration". So when following documentation examples, it overrides the object with a normal dict, thus the method 'get_all' doesn't exist. Maybe Microsoft is too good for dicts now.

I needed to do the following:
Before:

request_configuration = DetailsRequestBuilder.DetailsRequestBuilderPatchRequestConfiguration(
headers = {
		'Prefer' : "return=representation",
		'If-Match' : "W/\"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAWCc=\"",
})

After:

request_configuration = DetailsRequestBuilder.DetailsRequestBuilderPatchRequestConfiguration()
requestConfig.headers.try_add('Prefer','return=representation')
requestConfig.headers.try_add('If-Match','W/\"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAWCc=\"')              

Good luck,

@A360-Paul
Copy link

Adding some other findings regarding 'HeadersCollection' object/class.

The headers are now very sticky.
Once the headers have been added to the internal dict for the session, they persist between calls. Previously the dict would have wiped out when adding new headers (setting a new dict of headers, wiped old dict of headers). I needed to do this manually or my headers were polluted, resulting in subsequent requests throwing error on invalid ETAGs in my case.

Example from documentation (fixed):

...
request_configuration = DetailsRequestBuilder.DetailsRequestBuilderPatchRequestConfiguration()
requestConfig.headers.try_add('Prefer','return=representation')
requestConfig.headers.try_add('If-Match','W/\"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAWCc=\"')    
result = await graph_client.planner.tasks.by_planner_task_id('plannerTask-id').details.patch(request_body, request_configuration = request_configuration)
requestConfig.headers.remove('Prefer') #single session object holding header keys beyond one request, so we clear them
requestConfig.headers.remove('If-Match')

request_configuration = DetailsRequestBuilder.DetailsRequestBuilderPatchRequestConfiguration()
requestConfig.headers.try_add('Prefer','return=representation')
requestConfig.headers.try_add('If-Match','NEXT ETAG')    
result = await graph_client.planner.tasks.by_planner_task_id('plannerTask-id').details.patch(request_body, request_configuration = request_configuration)
requestConfig.headers.remove('Prefer') #single session object holding header keys beyond one request, so we clear them
requestConfig.headers.remove('If-Match')

Seems like a lot of garbage code in my opinion, but editing the dict directly was not working for me.
For example:

request_configuration = DetailsRequestBuilder.DetailsRequestBuilderPatchRequestConfiguration()
request_configuration.headers._headers = {
		'Prefer' : "return=representation",
		'If-Match' : "W/\"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAWCc=\"",
}

@tomaszsluszniak
Copy link

In my case, changing this code:

post_request_configuration = SubscriptionsRequestBuilder.SubscriptionsRequestBuilderPostRequestConfiguration(
    headers={
        "Prefer": 'IdType="ImmutableId"'
    }
)

to this:

post_request_configuration = SubscriptionsRequestBuilder.SubscriptionsRequestBuilderPostRequestConfiguration()
post_request_configuration.headers.try_add("Prefer", 'IdType="ImmutableId"')

solved the issue.

@andrueastman andrueastman added the bug Something isn't working label Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants