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

Baseurl path_parameter should be set on initialization #1034

Open
latalkdesk opened this issue Dec 16, 2024 · 2 comments
Open

Baseurl path_parameter should be set on initialization #1034

latalkdesk opened this issue Dec 16, 2024 · 2 comments
Labels
status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience

Comments

@latalkdesk
Copy link

Describe the bug

I am trying to get sites using with_url as first call, but an exception is thrown.

Expected behavior

No exception is thrown and the count of the sites is correct.

How to reproduce

import asyncio
import os
from azure.identity.aio import ClientSecretCredential
from msgraph import GraphServiceClient

credentials = ClientSecretCredential(
    "TENANT_ID",
    "CLIENT_ID",
    "CLIENT_SECRET",
)
client = GraphServiceClient(credentials=credentials)

async def get_sites_with_url():
    # workaround
    # client.path_parameters["baseurl"] = client.request_adapter.base_url
    print(f"Path parameters: {client.path_parameters}")
    url = client.sites.to_get_request_information().url
    print(f"Url: {url}")
    sites = await client.sites.with_url(url).get()
    print(f"#sites: {len(sites.value)}")

def main():
    asyncio.run(get_sites_with_url())

if __name__ == "__main__":
    main()

SDK Version

1.14.0

Latest version known to work for scenario above?

No response

Known Workarounds

Add baseurl to the client.path_parameters after creating the client.
like so: client.path_parameters["baseurl"] = client.request_adapter.base_url

Debug output

Path parameters: {'base_url': 'https://graph.microsoft.com/v1.0'}
Url: /sites
Traceback (most recent call last):
  File "/Users/luis.anselmo/projects/test.py", line 39, in <module>
    main()
  File "/Users/luis.anselmo/projects/test.py", line 35, in main
    asyncio.run(get_sites_with_url())
  File "/Users/luis.anselmo/.pyenv/versions/3.11.2/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Users/luis.anselmo/.pyenv/versions/3.11.2/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/luis.anselmo/.pyenv/versions/3.11.2/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/luis.anselmo/projects/test.py", line 30, in get_sites_with_url
    sites = await client.sites.with_url(url).get()
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/luis.anselmo/.pyenv/versions/3.11.2/lib/python3.11/site-packages/msgraph/generated/sites/sites_request_builder.py", line 71, in get
    return await self.request_adapter.send_async(request_info, SiteCollectionResponse, error_mapping)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/luis.anselmo/.pyenv/versions/3.11.2/lib/python3.11/site-packages/kiota_http/httpx_request_adapter.py", line 182, in send_async
    response = await self.get_http_response_message(request_info, parent_span)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/luis.anselmo/.pyenv/versions/3.11.2/lib/python3.11/site-packages/kiota_http/httpx_request_adapter.py", line 532, in get_http_response_message
    await self._authentication_provider.authenticate_request(
  File "/Users/luis.anselmo/.pyenv/versions/3.11.2/lib/python3.11/site-packages/kiota_abstractions/authentication/base_bearer_token_authentication_provider.py", line 50, in authenticate_request
    token = await self.access_token_provider.get_authorization_token(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/luis.anselmo/.pyenv/versions/3.11.2/lib/python3.11/site-packages/kiota_authentication_azure/azure_identity_access_token_provider.py", line 77, in get_authorization_token
    raise exc
kiota_authentication_azure._exceptions.HTTPError: Valid url scheme and host required

Configuration

  • OS: Mac 14.7.1 M1
  • Python 3.11.2

Other information

No response

@latalkdesk latalkdesk added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Dec 16, 2024
@latalkdesk latalkdesk changed the title Baseurl pathparameter should be set on initializtion Baseurl pathparameter should be set on initialization Dec 16, 2024
@latalkdesk latalkdesk changed the title Baseurl pathparameter should be set on initialization Baseurl path_parameter should be set on initialization Dec 17, 2024
@LuchiLucs
Copy link

@latalkdesk What would be a working example of the value of the url variabler elated to a given URL site? How would you map the actual URL with the needed input url of with_url?

@latalkdesk
Copy link
Author

@latalkdesk What would be a working example of the value of the url variabler elated to a given URL site? How would you map the actual URL with the needed input url of with_url?

When we do client.sites.to_get_request_information().url i would expect this to always return https://graph.microsoft.com/v1.0/sites. And it is not the case.

For instance:

print(client.sites.to_get_request_information().url) <- /sites
await client.sites.get()
print(client.sites.to_get_request_information().url) <- https://graph.microsoft.com/v1.0/sites

This happens because the client initial path_parameters only has base_url parameter and not baseurl so the url will return /sites since the SitesRequestBuilder has the template_url of {+baseurl}/sites{?%24count,%24expand,%24filter,%24orderby,%24search,%24select,%24skip,%24top}.

The url is correct on the second call because kiota sets the baseurl when we call client.sites.get() https://github.com/microsoft/kiota-http-python/blob/e37cdb3739e370c52536d8ab59ed65231ea4d9d1/kiota_http/httpx_request_adapter.py#L522

It seems like a bug.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience
Projects
None yet
Development

No branches or pull requests

2 participants