python-o365 icon indicating copy to clipboard operation
python-o365 copied to clipboard

Can't fetch calendar

Open gigibu5 opened this issue 3 years ago • 9 comments

Hi, I was just trying to use the example, but when I want to fetch the default calendar, I get the JSONDecodeError exception. Is this a bug? I have tried sending an email and that worked fine.

Here's the code:

#!/usr/bin/python3
from O365 import Account
import json

# GET config from config.json
f = open("./config.json")
config = json.loads(f.read())
f.close()

credentials = (config["app_id"], config["client_secret"])

account = Account(credentials)
schedule = account.schedule()

calendar = schedule.get_default_calendar() # I get the exception here
print(calendar)

I have granted this permisions on the Azure Portal: slika

gigibu5 avatar Feb 04 '21 14:02 gigibu5

Can you paste the error?

alejcas avatar Feb 15 '21 10:02 alejcas

I haven't touched this project for a while, I get this error now:

Exception has occurred: HTTPError

403 Client Error: Forbidden for url: https://graph.microsoft.com/v1.0/me/calendars?%24filter=name+eq+%27Koledar%27&%24top=1
Error Message: Access is denied. Check credentials and try again.

This is the new code:

from O365 import Account

credentials = ("Secret", "Secret")

account = Account(credentials)
m = account.new_message()
m.to.add('email@email')
m.subject = 'Testing!'
m.body = "George Best quote: I've stopped drinking, but only while I'm asleep."
m.send()

schedule = account.schedule()
print(schedule)
calendar = schedule.get_calendar(calendar_name='Koledar')
print(calendar)

It sends the email succsessfuly

gigibu5 avatar Feb 15 '21 10:02 gigibu5

Did you generate the oauth token?

with

if not account.is_authenticated:
    account.authenticate()

alejcas avatar Feb 15 '21 10:02 alejcas

Yes, I have. And I accepted premissions for email and calendar.

gigibu5 avatar Feb 15 '21 10:02 gigibu5

I have no clue here. It should allow the request but for some reason it responds with 403 Forbidden...

alejcas avatar Feb 15 '21 19:02 alejcas

Could you try it with your own credentials?

gigibu5 avatar Feb 15 '21 19:02 gigibu5

Could you try it with your own credentials?

It works perfectly for me.

alejcas avatar Feb 15 '21 20:02 alejcas

Hmmm, I will ask at my organization if they are blocking it or something. Thank you anyway.

gigibu5 avatar Feb 15 '21 20:02 gigibu5

@gigibu5 Did you find the solution? I am facing the same issue.

rathishkumar avatar Feb 22 '23 11:02 rathishkumar