Repository navigation
Baseurl path_parameter should be set on initialization #1034
Copy link
Copy link
Closed
Labels
priority:p2Medium. For a p2 bug, generally have a work-around. Bug SLA <=30 daysMedium. For a p2 bug, generally have a work-around. Bug SLA <=30 daystype:bugA broken experienceA broken experience
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
priority:p2Medium. For a p2 bug, generally have a work-around. Bug SLA <=30 daysMedium. For a p2 bug, generally have a work-around. Bug SLA <=30 daystype:bugA broken experienceA broken experience
Activity
[-]Baseurl pathparameter should be set on initializtion[/-][+]Baseurl pathparameter should be set on initialization[/+][-]Baseurl pathparameter should be set on initialization[/-][+]Baseurl path_parameter should be set on initialization[/+]LuchiLucs commentedon Dec 18, 2024
Luis Fernandes (@latalkdesk) What would be a working example of the value of the
urlvariabler elated to a given URL site? How would you map the actual URL with the needed inputurlofwith_url?latalkdesk commentedon Dec 18, 2024
When we do
client.sites.to_get_request_information().urli would expect this to always returnhttps://graph.microsoft.com/v1.0/sites. And it is not the case.For instance:
This happens because the client initial path_parameters only has
base_urlparameter and notbaseurlso the url will return/sitessince theSitesRequestBuilderhas 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#L522It seems like a bug.
Thanks.
ramnarayan-code commentedon Jan 29, 2025
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:
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
kgibson-spotnana commentedon Jan 29, 2025
I experienced the same bug on 1.9.1 and I believe originated from the
kiota_abstractions.base_request_configuration.RequestConfigurationmethod as that was my only kiota library use. Fixed by pinning the 1.9.0 version as ramnarayan-code did above.andrueastman commentedon Feb 17, 2025
Hey everyone,
The setting of the default base_url is resolved in microsoft/kiota-python#459.
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