service = discovery.build('admin', 'reports_v1', http=http_obj)
resp = service.channels().stop(body={}).execute()
Raises a googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/admin/reports/v1/admin/reports_v1/channels/stop? returned "Not Found">
I think the problem here is that this endpoint has a different URL format to the standard endpoint URL format, the correct URL for this endpoint is https://www.googleapis.com/admin/reports_v1/channels/stop, it has a underscore instead of a slash to separate the version.
It seems that the discovery API is aware of this because in https://www.googleapis.com/discovery/v1/apis/admin/reports_v1/rest all methods' paths do not start with a slash, except for the channels.stop()'s path that starts with a slash (/admin/reports_v1/channels/stop). Therefore I think this slash indicates that the whole URI should be replaced by the path, instead of appending the path to the base URL.
Having a look at the code I think this could be handled in googleapiclient.discovery._urljoin(). If the path starts with a slash replace the URI of the base URL with the path, instead of appending the path.
I have no idea on this one. @lukesneeringer @bjwatson any clues?
If anyone has the same problem. A quick and dirty workaround is:
service = discovery.build('admin', 'reports_v1', http=http_obj)
channels = service.channels()
# Remove the default URI of the base URL
channels._baseUrl = channels._baseUrl[:channels._baseUrl.find('/admin')]
# Now you can call channels.stop() and the endpoint will be correct
channels.stop(body={}).execute()
The analysis by @PacoHobi is correct, although the solution proposed in the OP may or may not be correct. There is a unit test that asserts the current behavior, which is to treat slash-prepended URLs as if they should just be appended to the base URL, and when the code is changed to treat the URL as if it already contains the base when it starts with a slash, the test fails.
https://github.com/google/google-api-python-client/blob/master/tests/test_discovery.py#L312
I'm going to need to dig up docs about the backend intent of slash-prefixed URLs, and either fix the test, or, if the current library behavior is correct, file a bug with the backend team.
Pretty sure this is going to need to go to the backend team, as it appears that slash-prefixed URLs are meant to be relative to the base URL, not the host or any other url.
Another solution to overcome this issue until it is being fixed:
from google.auth.transport.requests import AuthorizedSession
authed_session = AuthorizedSession(credentials)
response = authed_session.post("https://www.googleapis.com/admin/directory_v1/channels/stop", json = stopBody)
I also tried to use the credentials to authorize an httplib2 and use it, but didn't manage to make it working. If it can be used, it can be used in a very similar way to the AuthorizedSession solution
Just encountered this issue. Thanks @pacohh for the fix, it's working, but what's the deal on fixing the Python lib?
Hi @pacohh,
I ran the code below but I wan't able to re-produce the 404 error. It's likely that the issue is fixed. If you're still having trouble please re-open this issue with additional information.
service = discovery.build('admin', 'reports_v1', http=http_obj)
resp = service.channels().stop(body={}).execute()
Most helpful comment
If anyone has the same problem. A quick and dirty workaround is: