python-o365
python-o365 copied to clipboard
Can't fetch calendar
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:
Can you paste the error?
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
Did you generate the oauth token?
with
if not account.is_authenticated:
account.authenticate()
Yes, I have. And I accepted premissions for email and calendar.
I have no clue here. It should allow the request but for some reason it responds with 403 Forbidden...
Could you try it with your own credentials?
Could you try it with your own credentials?
It works perfectly for me.
Hmmm, I will ask at my organization if they are blocking it or something. Thank you anyway.
@gigibu5 Did you find the solution? I am facing the same issue.