import sys
import codecs, os
import google.ads.google_ads.client
import logging
logging.basicConfig(level=logging.INFO, format='[%(asctime)s - %(levelname)s] %(message).5000s')
logging.getLogger('google.ads.google_ads.client').setLevel(logging.INFO)
def main(client, customer_id, payment_account):
billing_setup_service = client.get_service('BillingSetupService',
version='v4')
billing_setup_operation = client.get_type('BillingSetupOperation',
version='v4')
billing_setup_operation.create = billing_setup_service.billing_setup_path(
customer_id, payment_account)
try:
billing_setup_response = billing_setup_service.mutate_billing_setup(
customer_id, billing_setup_operation)
except google.ads.google_ads.errors.GoogleAdsException as ex:
print('Request with ID "%s" failed with status "%s" and includes the '
'following errors:' % (ex.request_id, ex.error.code().name))
for error in ex.failure.errors:
print('\tError with message "%s".' % error.message)
if error.location:
for field_path_element in error.location.field_path_elements:
print('\t\tOn field: %s' % field_path_element.field_name)
sys.exit(1)
print('Removed billing setup %s.'
% billing_setup_response.results[0].resource_name)
def run():
# GoogleAdsClient will read the google-ads.yaml configuration file in the
# home directory if none is specified.
google_ads_client = (google.ads.google_ads.client.GoogleAdsClient
.load_from_storage("C:\\Users\\Kasper Aamodt\\PycharmProjects\\google-ads-master\\google-ads.yaml"))
customer_id = '
xxxxxxxxx'
payment_account = 'xxxxxxxxxxxxxxxx'
main(google_ads_client, customer_id, payment_account)
run()
That is the code i have, and it returns:
Traceback (most recent call last):
File "C:/Users/Kasper Aamodt/PycharmProjects/google-ads-master/in_use/connect_billing_account.py", line 60, in <module>
run()
File "C:/Users/Kasper Aamodt/PycharmProjects/google-ads-master/in_use/connect_billing_account.py", line 58, in run
main(google_ads_client, customer_id, payment_account)
File "C:/Users/Kasper Aamodt/PycharmProjects/google-ads-master/in_use/connect_billing_account.py", line 25, in main
billing_setup_operation.create = billing_setup_service.billing_setup_path(
File "C:\Users\Kasper Aamodt\Env\venv\lib\site-packages\google\protobuf\internal\python_message.py", line 766, in setter
raise AttributeError('Assignment not allowed to composite field '
AttributeError: Assignment not allowed to composite field "create" in protocol message object.