Skip to content

Misleading 501 MethodNotImplemented error when gRPC receives HTTP 404 #17683

Description

@guptaarima

Determine this is the right repository

  • I determined this is the correct repository in which to report this bug.

Summary of the issue:

Context:
When a gRPC call fails due to client-side configuration issues (such as a typo in the api_endpoint in ClientOptions and parent) using the BatchControllerClient in google-cloud-dataproc,, the client surfaces a misleading error message.

Expected Behavior:
google-api-core should raise an exception that better reflects the underlying HTTP 404. It should raise google.api_core.exceptions.NotFound (404) or google.api_core.exceptions.ServiceUnavailable (503) so the user knows to check their endpoint or resource path.

Actual Behavior:
The underlying error is grpc.StatusCode.UNIMPLEMENTED with the detail string "Received http2 header with status: 404". google-api-core translates this into google.api_core.exceptions.MethodNotImplemented, which masks the root cause and makes debugging difficult.

API client name and version

google-cloud-dataproc and google-api-core

Reproduction steps: code

from google.cloud import dataproc_v1
from google.api_core.client_options import ClientOptions

Provide an invalid/typo'd api_endpoint

options = ClientOptions(api_endpoint="invalid-dataproc.googleapis.com")
client = dataproc_v1.BatchControllerClient(client_options=options)

request = dataproc_v1.CreateBatchRequest(
parent="projects/dataproc-358205/locations/uc-central1",
batch=dataproc_v1.Batch()
)

This will trigger the misleading 501 error

client.create_batch(request=request)

Reproduction steps: supporting files

file: mydata.csv

alpha,1,3
beta,2,5

Reproduction steps: actual results

grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNIMPLEMENTED
details = "Received http2 header with status: 404"
debug_error_string = "UNIMPLEMENTED:Received http2 header with status: 404"

The above exception was the direct cause of the following exception:
google.api_core.exceptions.MethodNotImplemented: 501 Received http2 header with status: 404

Reproduction steps: expected results

google.api_core.exceptions.NotFound: 404 Received http2 header with status: 404.
(Or a similar error indicating that the endpoint or resource was not found, rather than MethodNotImplemented).

OS & version + platform

No response

Python environment

Python 3.11 / Python 3.12

Python dependencies

No response

Additional context

This issue originates from how google.api_core.exceptions.from_grpc_error maps status codes. It currently ignores the embedded "404" string in the details when returning MethodNotImplemented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions