Skip to content

Commit f6be6fd

Browse files
committed
Fix import paths in error handling examples
Change-Id: I860e515d5a945a47c03b603e1635d270e59f8b34
1 parent 88353fd commit f6be6fd

File tree

4 files changed

+34
-52
lines changed

4 files changed

+34
-52
lines changed

examples/error_handling/handle_keyword_policy_violations.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131

3232
from google.ads.googleads.client import GoogleAdsClient
3333
from google.ads.googleads.errors import GoogleAdsException
34-
from google.ads.googleads.v19.services.types.ad_group_criterion_service import (
34+
from google.ads.googleads.v20.services.services.ad_group_criterion_service import (
3535
AdGroupCriterionServiceClient,
3636
)
37-
from google.ads.googleads.v19.services.types.ad_group_criterion_operation import (
37+
from google.ads.googleads.v20.services.types.ad_group_criterion_service import (
3838
AdGroupCriterionOperation,
3939
)
40-
from google.ads.googleads.v19.common.types.policy import PolicyViolationKey
40+
from google.ads.googleads.v20.common.types.policy import PolicyViolationKey
4141

4242

4343
def main(
@@ -55,13 +55,11 @@ def main(
5555
keyword_text: The keyword text to add.
5656
"""
5757

58-
ad_group_criterion_service: AdGroupCriterionServiceClient = client.get_service(
59-
"AdGroupCriterionService"
58+
ad_group_criterion_service: AdGroupCriterionServiceClient = (
59+
client.get_service("AdGroupCriterionService")
6060
)
6161

62-
googleads_exception: Optional[
63-
GoogleAdsException
64-
]
62+
googleads_exception: Optional[GoogleAdsException]
6563
ad_group_criterion_operation: AdGroupCriterionOperation
6664
(
6765
googleads_exception,
@@ -79,9 +77,9 @@ def main(
7977
# your keyword contains many policy violations, but not all of them are
8078
# exemptible, the request will not be sent.
8179
if googleads_exception is not None:
82-
exempt_policy_violation_keys: List[
83-
PolicyViolationKey
84-
] = fetch_exempt_policy_violation_keys(googleads_exception)
80+
exempt_policy_violation_keys: List[PolicyViolationKey] = (
81+
fetch_exempt_policy_violation_keys(googleads_exception)
82+
)
8583
request_exemption(
8684
customer_id,
8785
ad_group_criterion_service,

examples/error_handling/handle_partial_failure.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,20 @@
2222

2323
from google.ads.googleads.client import GoogleAdsClient
2424
from google.ads.googleads.errors import GoogleAdsException
25-
from google.ads.googleads.v19.services.types.ad_group_service import (
25+
from google.ads.googleads.v20.services.services.ad_group_service import (
2626
AdGroupServiceClient,
2727
)
28-
from google.ads.googleads.v19.services.types.campaign_service import (
28+
from google.ads.googleads.v20.services.services.campaign_service import (
2929
CampaignServiceClient,
3030
)
31-
from google.ads.googleads.v19.services.types.ad_group_operation import (
31+
from google.ads.googleads.v20.services.types.ad_group_service import (
3232
AdGroupOperation,
33-
)
34-
from google.ads.googleads.v19.services.types.mutate_ad_groups_response import (
3533
MutateAdGroupsResponse,
36-
)
37-
from google.ads.googleads.v19.services.types.mutate_ad_groups_request import (
3834
MutateAdGroupsRequest,
3935
)
4036

4137

42-
def main(
43-
client: GoogleAdsClient, customer_id: str, campaign_id: str
44-
) -> None:
38+
def main(client: GoogleAdsClient, customer_id: str, campaign_id: str) -> None:
4539
"""Runs the example code, which demonstrates how to handle partial failures.
4640
4741
The example creates three Ad Groups, two of which intentionally fail in

examples/error_handling/handle_rate_exceeded_error.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,16 @@
2929

3030
from google.ads.googleads.client import GoogleAdsClient
3131
from google.ads.googleads.errors import GoogleAdsException
32-
from google.ads.googleads.v19.enums.types.quota_error import QuotaErrorEnum
33-
from google.ads.googleads.v19.services.types.ad_group_service import (
32+
from google.ads.googleads.v20.errors.types.quota_error import QuotaErrorEnum
33+
from google.ads.googleads.v20.services.services.ad_group_service import (
3434
AdGroupServiceClient,
3535
)
36-
from google.ads.googleads.v19.services.types.ad_group_criterion_service import (
36+
from google.ads.googleads.v20.services.services.ad_group_criterion_service import (
3737
AdGroupCriterionServiceClient,
3838
)
39-
from google.ads.googleads.v19.services.types.ad_group_criterion_operation import (
39+
from google.ads.googleads.v20.services.types.ad_group_criterion_service import (
4040
AdGroupCriterionOperation,
41-
)
42-
from google.ads.googleads.v19.services.types.mutate_ad_group_criteria_request import (
4341
MutateAdGroupCriteriaRequest,
44-
)
45-
from google.ads.googleads.v19.services.types.mutate_ad_group_criteria_response import (
4642
MutateAdGroupCriteriaResponse,
4743
)
4844

@@ -56,9 +52,7 @@
5652
RETRY_SECONDS: int = 10
5753

5854

59-
def main(
60-
client: GoogleAdsClient, customer_id: str, ad_group_id: str
61-
) -> None:
55+
def main(client: GoogleAdsClient, customer_id: str, ad_group_id: str) -> None:
6256
"""Runs the example code, which shows how to handle rate exceeded errors.
6357
6458
Args:
@@ -75,10 +69,10 @@ def main(
7569
)
7670

7771
for i in range(NUM_REQUESTS):
78-
operations: List[
79-
AdGroupCriterionOperation
80-
] = create_ad_group_criterion_operations(
81-
client, customer_id, ad_group_id, i
72+
operations: List[AdGroupCriterionOperation] = (
73+
create_ad_group_criterion_operations(
74+
client, customer_id, ad_group_id, i
75+
)
8276
)
8377

8478
try:
@@ -165,7 +159,7 @@ def create_ad_group_criterion_operations(
165159
ad_group_criterion_operation: AdGroupCriterionOperation = (
166160
client.get_type("AdGroupCriterionOperation")
167161
)
168-
ad_group_criterion: AdGroupCriterionOperation.create = (
162+
ad_group_criterion: AdGroupCriterion = (
169163
ad_group_criterion_operation.create
170164
)
171165
ad_group_criterion.ad_group = ad_group_service.ad_group_path(

examples/error_handling/handle_responsive_search_ad_policy_violations.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,30 @@
2525

2626
from google.ads.googleads.client import GoogleAdsClient
2727
from google.ads.googleads.errors import GoogleAdsException
28-
from google.ads.googleads.v19.services.types.ad_group_ad_service import (
28+
from google.ads.googleads.v19.services.services.ad_group_ad_service import (
2929
AdGroupAdServiceClient,
3030
)
31-
from google.ads.googleads.v19.services.types.ad_group_service import (
31+
from google.ads.googleads.v19.services.services.ad_group_service import (
3232
AdGroupServiceClient,
3333
)
34-
from google.ads.googleads.v19.services.types.ad_group_ad_operation import (
34+
from google.ads.googleads.v19.services.types.ad_group_ad_service import (
3535
AdGroupAdOperation,
36+
MutateAdGroupAdsResponse,
3637
)
3738
from google.ads.googleads.v19.resources.types.ad_group_ad import AdGroupAd
3839
from google.ads.googleads.v19.common.types.ad_type_infos import (
3940
ResponsiveSearchAdInfo,
41+
)
42+
from google.ads.googleads.v19.common.types.ad_asset import (
4043
AdTextAsset,
4144
)
42-
from google.ads.googleads.v19.enums.types.policy_finding_error import (
45+
from google.ads.googleads.v19.errors.types.policy_finding_error import (
4346
PolicyFindingErrorEnum,
4447
)
45-
from google.ads.googleads.v19.services.types.mutate_ad_group_ads_response import (
46-
MutateAdGroupAdsResponse,
47-
)
4848

4949

50-
def main(
51-
client: GoogleAdsClient, customer_id: str, ad_group_id: str
52-
) -> None:
53-
"""Uses Customer Match to create and add users to a new user list.
50+
def main(client: GoogleAdsClient, customer_id: str, ad_group_id: str) -> None:
51+
"""Handles responsive search ad policy violations.
5452
5553
Args:
5654
client: The Google Ads client.
@@ -168,9 +166,7 @@ def fetch_ignorable_policy_topics(
168166
for error in googleads_exception.failure.errors:
169167
if (
170168
error.error_code.policy_finding_error
171-
!= client.get_type(
172-
"PolicyFindingErrorEnum"
173-
).PolicyFindingError.POLICY_FINDING
169+
!= client.enums.PolicyFindingErrorEnum.POLICY_FINDING
174170
):
175171
print(
176172
"This example supports sending exemption request for the "
@@ -283,4 +279,4 @@ def request_exemption(
283279
if error.location:
284280
for field_path_element in error.location.field_path_elements:
285281
print(f"\t\tOn field: {field_path_element.field_name}")
286-
sys.exit(1)
282+
sys.exit(1)

0 commit comments

Comments
 (0)