Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: 'tuple' object does not support item assignment #67

Closed
jkcso opened this issue Nov 16, 2017 · 9 comments
Closed

TypeError: 'tuple' object does not support item assignment #67

jkcso opened this issue Nov 16, 2017 · 9 comments

Comments

@jkcso
Copy link

jkcso commented Nov 16, 2017

The error is here:
self.json['Subject'] = val

I think your codebase has an error which I am getting from here:
e = Event(authenticiation)
e.setSubject('coffee') # <- THIS LINE
e.setStart(time.gmtime(time.time()+3600)) #start an hour from now.
e.setEnd(time.gmtime(time.time()+7200)) #end two hours from now.
new_e = e.create()

Note that e.setStart(..) line and the following returns the same error.

@Narcolapser
Copy link
Member

Can you include your stack trace?

@jkcso
Copy link
Author

jkcso commented Nov 16, 2017

hi, i just realised that i was not using a schedule to retrieve a calendar, can you help on what I am missing?

schedule = Schedule(authentication)
result = schedule.calendars
print(result)

CALENDAR

ev = Event(authentication)
ev.setSubject('coffee')
ev.setStart(time.gmtime(time.time() + 3600)) # start an hour from now.
ev.setEnd(time.gmtime(time.time() + 7200)) # end two hours from now.
new_e = ev.create()

I am trying to understand how to get a calendar from a scheduler and pass it to event.create

@Narcolapser
Copy link
Member

Well, the library does a lazy load, so you need to get the calendars like this:

result = schedule.getCalendars()

Then you create the event with the calendar of your choosing, assuming you only have one, it should look something like this:

result = schedule.getCalendars()
ev = Event(auth=authentication,cal=result[0])

It's a bit of a wonky system I'll admit. It's largely because I'm just exposing the API in Python fairly directly. I'm starting to realize I need to rewrite this to work in a more sensible way.

@jkcso
Copy link
Author

jkcso commented Nov 16, 2017

hey again and thank you but this line:
result = schedule.getCalendars() is a boolean

@Narcolapser
Copy link
Member

oh, hehe, sorry. It's been a while clearly. This should work:

schedule = Schedule(authentication)
schedule.getCalendars()
result = schedule.calendars

@jkcso
Copy link
Author

jkcso commented Nov 16, 2017

Still same issue, ill show you all my code to understand what I am trying to do. So I am trying to see if your library is suitable for posting and getting events for my web application, what I am having now is this:

authentication = (e, p)  // e is my mail and p is my password

bookings = []
json_outs = {}

schedule = Schedule(authentication)
try:
    result = schedule.getCalendars()
    print('\nFetched calendars for', e, 'was successful:', result, '\n')
except:
    print('Login failed for', e, '\n')

for cal in schedule.calendars:
    print('Attempting to fetch events for', e, '\n')
    try:
        result = cal.getEvents()
        print('Got:', len(cal.events), 'events in total from given calendar')
    except:
        print('failed to fetch events')
    print('\nAttempting for event information, events I got: \n')
    for event in cal.events:
        bookings.append(event.fullcalendarioJson())
json_outs[e] = bookings

print(bookings[0])
print(bookings[1])
print(bookings[2])

schedule = Schedule(authentication)
schedule.getCalendars()
result = schedule.calendars
ev = Event(authentication, result[0])
ev.setSubject('coffee')
ev.setStart(time.gmtime(time.time() + 3600))  # start an hour from now.
ev.setEnd(time.gmtime(time.time() + 7200))  # end two hours from now.
new_e = ev.create()

It fetches the events and I indeed have them in a dictionary but when i go to "ev." lines I have the following error with the program output being this:

Traceback (most recent call last):
File "/Users/jk/Documents/ExchangeTesting/narcolapser.py", line 46, in
ev.setSubject('coffee')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/O365/event.py", line 223, in setSubject
self.json['Subject'] = val
TypeError: 'tuple' object does not support item assignment

Process finished with exit code 1

@Narcolapser
Copy link
Member

your problem is in instantiation of Event. Because the constructor for Event uses key word arguments, authentication and your calendar aren't going to the right places. The method declaration looks like this:

def __init__(self,json=None,auth=None,cal=None,verify=True):

If you don't assign the key word arguments, it just does them in order. Which means you are passing in your authentication tuple as the json, and your calendar as authentication. Try updating your event line to this:

ev = Event(auth=authentication, cal=result[0])

@jkcso
Copy link
Author

jkcso commented Nov 16, 2017

It worked, cheers for you fast and effective responses mate!

@Narcolapser
Copy link
Member

No problem. Glad to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants