Skip to content

Baseurl path_parameter should be set on initialization #1034

Closed

Description

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

Activity

  1. changed the title [-]Baseurl pathparameter should be set on initializtion[/-] [+]Baseurl pathparameter should be set on initialization[/+] on Dec 16, 2024
  2. changed the title [-]Baseurl pathparameter should be set on initialization[/-] [+]Baseurl path_parameter should be set on initialization[/+] on Dec 17, 2024
  3. LuchiLucs commented on Dec 18, 2024

    @LuchiLucs

    Luis Fernandes (@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?

  4. latalkdesk commented on Dec 18, 2024

    @latalkdesk
    Author

    Luis Fernandes (@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.

  5. ramnarayan-code commented on Jan 29, 2025

    @ramnarayan-code

    Despite this issue was reported 1 month back, we were impacted by the equivalent issue today.

    Due to the release of microsoft-kiota-abstractions==1.9.1 today, we got the same exception below:

     File "/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages/kiota_http/httpx_request_adapter.py", line 186, in send_async
        response = await self.get_http_response_message(request_info, parent_span)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages/kiota_http/httpx_request_adapter.py", line 595, in get_http_response_message
        await self._authentication_provider.authenticate_request(
      File "/opt/hostedtoolcache/Python/3.11.11/x64/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 "/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages/kiota_authentication_azure/azure_identity_access_token_provider.py", line 78, in get_authorization_token
        raise exc
    kiota_authentication_azure._exceptions.HTTPError: Valid url scheme and host required
    
    
    

    Rootcause
    Site URL is messed up like:
    in 1.9.0, self.client.sites.to_get_request_information().urlused to be "/sites" (works fine)
    in 1.9.1, it shows as "NationalClouds.Global/APIVersion.v1//sites" (exception root cause)

    Workaround:
    Installed the last working version microsoft-kiota-abstractions==1.9.0 and it works

  6. kgibson-spotnana commented on Jan 29, 2025

    @kgibson-spotnana

    I experienced the same bug on 1.9.1 and I believe originated from the kiota_abstractions.base_request_configuration.RequestConfiguration method as that was my only kiota library use. Fixed by pinning the 1.9.0 version as ramnarayan-code did above.

  7. andrueastman commented on Feb 17, 2025

    @andrueastman
    Contributor

    Hey everyone,
    The setting of the default base_url is resolved in microsoft/kiota-python#459.

    in 1.9.1, it shows as "NationalClouds.Global/APIVersion.v1//sites" (exception root cause)

    The root cause of the issue is outlined in microsoft/kiota-python#470 (comment).

    This issue was fortunately already been resolved in microsoftgraph/msgraph-sdk-python-core#820 and therefore the solution here it to ensure that your dependency tree has msgraph-core version 1.2.1 or greater.

    https://github.com/microsoftgraph/msgraph-sdk-python-core/releases/tag/v1.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

priority:p2Medium. For a p2 bug, generally have a work-around. Bug SLA <=30 daystype:bugA broken experience

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions