question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Admin SDK Reports API channels.stop() 404 because of wrong API URL

See original GitHub issue

Problem

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">

Problem notes

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.

Possible solution

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.

Notes

  • Having said that, I don’t know if the rule “If the discovery API says that a method’s path starts with a slash then this path must replace the URI of the base URL” is true for all APIs.
  • Seems like the URL in the documentation is also wrong, but I guess this is not the correct place to report that.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
pacohhcommented, Jun 8, 2017

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()
1reaction
partheacommented, Dec 8, 2020

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()
Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Reports API channels.stop returns 404 Error
When using google-api-python-client to stop receiving push notifications, it returns Error 404: Channel not found.
Read more >
Error Messages | Maps JavaScript API - Google Developers
You may have supplied an invalid channel parameter. The channel must be an ASCII alphanumeric string, which may include period (.), underscore (_)...
Read more >
HTTP status and error codes for JSON | Cloud Storage
The following document provides reference information about the status codes and error messages that are used in the Cloud Storage JSON API.
Read more >
Web API implementation - Best practices for cloud applications
The first DELETE request might return status code 204 (No Content), while a subsequent DELETE request might return status code 404 (Not Found)....
Read more >
Authentication API Explorer - Auth0
If response_type=token , after the user authenticates on the provider, it will redirect to your application callback URL passing the Access Token and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found