campaignmonitor / createsend-python

A Python library for the Campaign Monitor API
http://campaignmonitor.github.io/createsend-python
MIT License
57 stars 63 forks source link

client.campaigns() TypeError: 'type' object is not iterable #77

Open Esnilg opened 2 years ago

Esnilg commented 2 years ago

hello

when i run

cs = CreateSend(auth)

clients = cs.clients() campaign_ids = cs.clients()

for cl in clients: print("Client: %s" % cl.Name) client = Client(auth, cl.ClientID) print("- Campaigns:") for cm in client.campaigns(): print(" - %s" % cm.Subject) print(" - %s" % cm.CampaignID)

i have this issue

File "C:\Users\eguevara\AppData\Local\Temp/ipykernel_17348/3998498663.py", line 1, in for i in client.campaigns():

TypeError: 'type' object is not iterable

ghost commented 2 years ago

I had the same issue. An older installation with createsend pip 6.1.2 module works well, with createsend 7.0.0 the same code doesn't work anymore. According to the release notes:

Breaking: 'client.campaigns' now returned an object to support pagination (use .Results to get the array of campaigns)

for cm in client.campaigns().Results:

This works !

Mingzhao-Lin commented 1 year ago

It's happening to me as well. Looks like this wrapper isn't updated. Anyone lucky in acquiring list of campaignIds?

ghost commented 1 year ago

It's happening to me as well. Looks like this wrapper isn't updated. Anyone lucky in acquiring list of campaignIds?

As said, use .Results

for cl in clients: client = Client({'api_key': ''}, cl.ClientID) for cm in client.campaigns().Results: campaign = Campaign({'api_key': ''}, cm.CampaignID) cx=campaign.summary()

Mingzhao-Lin commented 1 year ago

It's happening to me as well. Looks like this wrapper isn't updated. Anyone lucky in acquiring list of campaignIds?

As said, use .Results

for cl in clients: client = Client({'api_key': ''}, cl.ClientID) for cm in client.campaigns().Results: campaign = Campaign({'api_key': ''}, cm.CampaignID) cx=campaign.summary()

Hi Thanks speedy! Turns out it's because i used a differnt funciton to get client:

auth = (username, password)
...
client = Client(auth, cl.ClientID)

changed it to client = Client({'api_key': ''}, cl.ClientID) and now it's working

Thanks for the headsup