google-ads-python: google.api_core.exceptions.MethodNotImplemented: 501 GRPC target method can't be resolved

Describe the bug:

Hello,

I’m new at Google API, and I was trying to test KeywordPlanIdeaService. I try to follow the example provided in your doc (https://developers.google.com/google-ads/api/docs/keyword-planning/generate-keyword-ideas?hl=fr#python), removing stuff about which I don’t know values to give.

But I get this error: google.api_core.exceptions.MethodNotImplemented: 501 GRPC target method can’t be resolved.

Steps to Reproduce:

Here is the final code:

from google.ads.googleads.client import GoogleAdsClient import json

class ApiGoogleAds: CREDENTIALS_FILE = “config/google-ads-credentials.json” API_KEY = “…” # Api_key in google console for public data credentials = None client = None

def __init__(
    self,
):
    with open(self.CREDENTIALS_FILE, "r") as outfile:
        self.credentials = json.load(outfile)

    self.client = GoogleAdsClient.load_from_storage(self.CREDENTIALS_FILE)

def get_keyword_ideas(self, keywords: str = "", url: str = ""):
    keyword_plan_idea_service = self.client.get_service("KeywordPlanIdeaService")
    keyword_plan_network = (
        self.client.enums.KeywordPlanNetworkEnum.GOOGLE_SEARCH_AND_PARTNERS
    )

    if not (keywords or url):
        raise ValueError(
            "At least one of keywords or page URL is required, "
            "but neither was specified."
        )

    request = self.client.get_type("GenerateKeywordIdeasRequest")
    request.customer_id = self.credentials["login_customer_id"]
    request.include_adult_keywords = False
    request.keyword_plan_network = keyword_plan_network

    if keywords and url:
        request.keyword_and_url_seed.url = url
        request.keyword_and_url_seed.keywords.extend(keywords)
    elif keywords:
        request.keyword_seed.keywords.extend(keywords)
    elif url:
        request.url_seed.url = url

    keyword_ideas = keyword_plan_idea_service.generate_keyword_ideas(
        request=request
    )

    for idea in keyword_ideas:
        competition_value = idea.[keyword_idea_metrics.competition.name](http://keyword_idea_metrics.competition.name/)
        print(
            f'Keyword idea text "{idea.text}" has '
            f'"{idea.keyword_idea_metrics.avg_monthly_searches}" '
            f'average monthly searches and "{competition_value}" '
            "competition.\n"
        )

if name == “main”: …

And then, my testing script :

python -m scripts.test_google_ads

from crawlers.api.api_google_ads import ApiGoogleAds

apiAds = ApiGoogleAds() apiAds.get_keyword_ideas(keywords=“bottes en cuir”)

Expected behavior:

No error, or clear params/config error if I missed some params.

Client library version and API version: Client library version: Python 3.9.18 Google Ads API version: google-ads==21.3.0

Request/Response Logs:

And when I run it, I have the following exception: Request made: ClientCustomerId: 2416036531, Host: googleads.googleapis.com, Method: /google.ads.googleads.v14.services.KeywordPlanIdeaService/GenerateKeywordIdeas, RequestId: None, IsFault: True, FaultMessage: GRPC target method can’t be resolved. Traceback (most recent call last): File “/Projects/data/venv/lib/python3.9/site-packages/google/api_core/grpc_helpers.py”, line 75, in error_remapped_callable return callable_(*args, **kwargs) File “/Projects/data/venv/lib/python3.9/site-packages/grpc/_interceptor.py”, line 277, in call response, ignored_call = self._with_call( File “/Projects/data/venv/lib/python3.9/site-packages/grpc/_interceptor.py”, line 332, in _with_call return call.result(), call File “/Projects/data/venv/lib/python3.9/site-packages/grpc/_channel.py”, line 438, in result raise self File “/Projects/data/venv/lib/python3.9/site-packages/grpc/_interceptor.py”, line 315, in continuation response, call = self._thunk(new_method).with_call( File “/Projects/data/venv/lib/python3.9/site-packages/grpc/_interceptor.py”, line 343, in with_call return self._with_call( File “/Projects/data/venv/lib/python3.9/site-packages/grpc/_interceptor.py”, line 332, in _with_call return call.result(), call File “/Projects/data/venv/lib/python3.9/site-packages/grpc/_channel.py”, line 438, in result raise self File “/Projects/data/venv/lib/python3.9/site-packages/grpc/_interceptor.py”, line 315, in continuation response, call = self._thunk(new_method).with_call( File “/Projects/data/venv/lib/python3.9/site-packages/grpc/_interceptor.py”, line 343, in with_call return self._with_call( File “/Projects/data/venv/lib/python3.9/site-packages/grpc/_interceptor.py”, line 329, in _with_call call = self._interceptor.intercept_unary_unary( File “/Projects/data/venv/lib/python3.9/site-packages/google/ads/googleads/interceptors/exception_interceptor.py”, line 99, in intercept_unary_unary self._handle_grpc_failure(response) File “/Projects/data/venv/lib/python3.9/site-packages/google/ads/googleads/interceptors/exception_interceptor.py”, line 71, in _handle_grpc_failure raise self._get_error_from_response(response) File “/Projects/data/venv/lib/python3.9/site-packages/grpc/_interceptor.py”, line 315, in continuation response, call = self._thunk(new_method).with_call( File “/Projects/data/venv/lib/python3.9/site-packages/grpc/_channel.py”, line 1178, in with_call return _end_unary_response_blocking(state, call, True, None) File “/Projects/data/venv/lib/python3.9/site-packages/grpc/_channel.py”, line 1004, in _end_unary_response_blocking raise _InactiveRpcError(state) # pytype: disable=not-instantiable grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.UNIMPLEMENTED details = “GRPC target method can’t be resolved.” debug_error_string = “UNKNOWN:Error received from peer ipv6:%5B2a00:1450:4006:804::200a%5D:443 {created_time:“2024-11-15T14:43:51.013252+01:00”, grpc_status:12, grpc_message:“GRPC target method can't be resolved.”}”

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File “/usr/local/Cellar/python@3.9/3.9.18_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py”, line 197, in _run_module_as_main return _run_code(code, main_globals, None, File “/usr/local/Cellar/python@3.9/3.9.18_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py”, line 87, in _run_code exec(code, run_globals) File “/Projects/data/scripts/test_google_ads.py”, line 5, in apiAds.get_keyword_ideas(keywords=“bottes en cuir”) File “/Projects/data/crawlers/api/api_google_ads.py”, line 70, in get_keyword_ideas keyword_ideas = keyword_plan_idea_service.generate_keyword_ideas( File “/Projects/data/venv/lib/python3.9/site-packages/google/ads/googleads/v14/services/services/keyword_plan_idea_service/client.py”, line 455, in generate_keyword_ideas response = rpc( File “/Projects/data/venv/lib/python3.9/site-packages/google/api_core/gapic_v1/method.py”, line 131, in call return wrapped_func(*args, **kwargs) File “/Projects/data/venv/lib/python3.9/site-packages/google/api_core/grpc_helpers.py”, line 77, in error_remapped_callable raise exceptions.from_grpc_error(exc) from exc google.api_core.exceptions.MethodNotImplemented: 501 GRPC target method can’t be resolved.

I tried to look a bit if I found similar troubles reports, but either it’s not matching mine, or I misunderstand things…

Could you please help me a bit ? Sorry if my knowledge level about Google tools, even just development skills, are not very good, or even my english level.

Anything else we should know about your project / environment:

Thanks for the help you will provide.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 15 (1 by maintainers)

Most upvoted comments

Same behavior here! Need a fix!

Any updates here? I’m following https://github.com/googleads/google-ads-python/blob/main/examples/remarketing/upload_offline_conversion.py and getting

Request made: ClientCustomerId: ..., Host: googleads.googleapis.com, Method: /google.ads.googleads.v14.services.ConversionUploadService/UploadClickConversions, RequestId: None, IsFault: True, FaultMessage: GRPC target method can't be resolved.

@lgaleana did you solve it ?

Hey can you try installing the latest version? Using the pip installer it defaulted to v21, if you can specify the latest version 25.1.0 it should work. lmk !

from google.ads.google_ads.client import GoogleAdsClient
from google.ads.google_ads.errors import GoogleAdsException

def upload_offline_conversions(client, customer_id, conversions):
    # Get the ConversionUploadService
    conversion_upload_service = client.get_service('ConversionUploadService')

    # Create a list of ClickConversion objects
    click_conversions = []
    for conversion in conversions:
        click_conversion = client.get_type('ClickConversion')
        click_conversion.conversion_action = client.get_service('ConversionActionService').conversion_action_path(
            customer_id, conversion['conversion_action_id']
        )
        click_conversion.gclid = conversion['gclid']
        click_conversion.conversion_date_time = conversion['conversion_time']
        click_conversion.conversion_value = float(conversion['conversion_value'])
        click_conversion.currency_code = conversion['currency_code']
        click_conversions.append(click_conversion)

    # Upload the conversions
    try:
        response = conversion_upload_service.upload_click_conversions(
            customer_id=customer_id,
            conversions=click_conversions,
            partial_failure=True
        )
        # Print results
        for result in response.results:
            print(f"Uploaded conversion for GCLID: {result.gclid}")
    except GoogleAdsException as ex:
        print(f"Request failed with status {ex.error.code().name}")
        print(f"Error message: {ex.error.message}")
        # Print specific errors
        for error in ex.failure.errors:
            print(f"Error: {error.error_code}, Message: {error.message}")

# Example usage
def main():
    # Load the Google Ads client
    client = GoogleAdsClient.load_from_storage()

    # Replace with your Google Ads customer ID
    customer_id = 'INSERT_CUSTOMER_ID_HERE'

    # Example conversion data
    conversions = [
        {
            'conversion_action_id': 'INSERT_CONVERSION_ACTION_ID_HERE',
            'gclid': 'INSERT_GCLID_HERE',
            'conversion_time': '2023-10-15 12:34:56+00:00',
            'conversion_value': '100.0',
            'currency_code': 'USD'
        },
        # Add more conversions as needed
    ]

    # Upload offline conversions
    upload_offline_conversions(client, customer_id, conversions)

if __name__ == '__main__':
    main()

and when i tried to install pip install google-ads==25.1.0 ERROR: Could not find a version that satisfies the requirement google-ads==25.1.0 (from versions: 0.1.0, 0.2.0, 0.3.0, 0.4.0, 0.5.0, 0.5.1, 0.5.2, 0.6.0, 0.7.0, 1.0.0, 1.0.1, 1.1.0, 1.1.1, 1.2.0, 1.3.0, 1.3.1, 2.0.0, 2.1.0, 2.2.0, 2.3.0, 2.4.0, 2.4.1, 3.0.0, 3.1.0, 3.1.1, 3.1.2, 3.2.0, 3.3.0, 4.0.0, 4.1.0, 4.1.1, 5.0.0, 5.0.1, 5.0.2, 5.0.3, 5.0.4, 5.1.0, 6.0.0, 7.0.0, 8.0.0, 8.1.0, 8.2.0, 9.0.0, 10.0.0, 11.0.0, 11.0.1, 11.0.2, 12.0.0, 13.0.0, 14.0.0, 14.0.1, 14.1.0, 15.0.0, 15.1.0, 15.1.1, 16.0.0, 17.0.0, 18.0.0, 18.1.0, 18.2.0, 19.0.0, 20.0.0, 21.0.0, 21.1.0, 21.2.0, 21.3.0, 22.0.0) ERROR: No matching distribution found for google-ads==25.1.0 @Eric-WK can you please guide , my motive is to upload offline conversion using api

Hey, are you able to install it directly from the repo?

I was able but now it didn’t recognize:

from google.ads.googleads.client import GoogleAdsClient
from google.ads.googleads.errors import GoogleAdsException

to successfully install the repo version, you need to have python 3.12.0

Hi, was able to solve the error by uninstalling and installing the latest release:

!uv add google-ads==25.1.0