Closed jaehancrate closed 6 years ago
I noticed a few minor issues that seem unrelated, but I was not able to reproduce with the following roughly-equivalent script:
import uuid
import googleads.adwords
def main(client):
user_list_service = client.GetService('AdwordsUserListService')
user_list = {
'xsi_type': 'CrmBasedUserList',
'name': 'Customer Match Home Address Test List #%d' % uuid.uuid4(),
'description': 'Customer Match by Home Address Test Group',
'membershipLifeSpan': 180
}
operations = [{
'operator': 'ADD',
'operand': user_list
}]
result = user_list_service.mutate(operations)
user_list_id = result['value'][0]['id']
print 'Created Audience with User List ID: %d' % user_list_id
if __name__ == '__main__':
main(googleads.adwords.AdWordsClient.LoadFromStorage())
I suspect this may have to do with your Anaconda installation; e.g. perhaps the version of suds (or other dependencies) installed does not match the version specified in our setup.py.
I have run the setup.py install already..... I am still getting token not found error
This is the complete Code:
from googleads import adwords
import hashlib
import uuid
import pandas as pd
def NormalizeAndSHA256(s): """Normalizes (lowercase, remove whitespace) and hashes a string with SHA-256. Args: s: The string to perform this operation on. Returns: A normalized and SHA-256 hashed string. """ return hashlib.sha256(s.strip().lower()).hexdigest()
list_of_names_control = pd.read_csv('FILE_1_RETAIL_ONLY_CONTROL_HOME ADDRESS ONLY.csv', sep=',', encoding='utf-8') list_of_names_control = list_of_names_control[['First Name', 'Last Name', 'ZIP']]
list_of_names_test = pd.read_csv('FILE_1_RETAIL_ONLY_TEST_HOME ADDRESS ONLY.csv', sep=',', encoding='utf-8') list_of_names_test = list_of_names_test[['First Name', 'Last Name', 'ZIP']]
names_test = list_of_names_test.to_dict(orient='record') names_control = list_of_names_control.to_dict(orient='record')
adwords_client = adwords.AdWordsClient.LoadFromStorage('googleads.yaml') user_list_service = adwords_client.GetService('AdwordsUserListService', 'v201710')
print("Creating Audience Now") user_list = { 'xsi_type': 'CrmBasedUserList', 'name': 'Customer Match Home Address Test List #%d' % uuid.uuid4(), 'description': 'Customer Match by Home Address Test Group', 'membershipLifeSpan': 180 }
operations = [{ 'operator': 'ADD', 'operand': user_list }]
print('Creating the User List') print(operations)
user_list_service.get(operations) result = user_list_service.mutate(operations) user_list_id = result['value'][0]['id']
print('Created Audience with User List ID: %d' % user_list_id)
members = [] print('Adding data to members list for upload to user list....') for d in names_test: members.append({ 'addressInfo': { 'hashedFirstName': NormalizeAndSHA256(d['First Name']), 'hashedLastName': NormalizeAndSHA256(d['Last Name']), 'countryCode': 'US', 'zipCode': d['ZIP'] } })
mutate_members_operation = { 'operand': { 'userListId': user_list_id, 'membersList': members }, 'operator': 'ADD' }
response = user_list_service.mutateMembers([mutate_members_operation])
if 'userLists' in response:
for user_list in response['userLists']:
print ('User list with name "%s" and ID "%d" was added.'
% (user_list['name'], user_list['id']))
SOLVED: There was an issue in an older version (I think, I could be wrong) of the the googleads github where I was calling:
user_list_service.get(operations)
This does not exist in the newer version. Upon removing the line I was able to upload successfully. Thanks!
Having issues getting the user_service_list .. The issue says: TypeNotFound: Type not found: 'operator'
It errs out on the user_list_service.get(operations) line
Am I missing something here?