Closed Bakura01 closed 2 months ago
My temporary fix:
# new try using a direct get request --> Does work but only with the access token
# todo refresh token somehow for every time the code runs
self.token = (self.account.connection.token_backend.load_token())["access_token"]
directUrl = f"https://graph.microsoft.com/v1.0/users/{self.email}/mailFolders/Inbox/messages"
headers = {
"Authorization" : f"{self.token}",
"ContentType": "application/json"
}
try:
response = requests.get(url=directUrl,headers=headers)
# todo check for what is gotten back by the api
# email count is wrong because it reads all objects i only need names or something of that sort
for email in response:
print(email)
self.emailCount += 1
print("New messages: ",str(self.emailCount)," at ",str(datetime.datetime.now()))
return self.emailCount
except Exception:
print(Exception)
That fixes the request, because i explicitly send only the access token my self not with this library but as such i cannot refresh my access token with it for some reason
I just noticed that my the session object has no access token stored. I don't know what happened i do load the token and return it ? --> Fix: load the session when creating an account object
I don't have enough data to answer you.
Is this program run on a server or just on your machine?
Thank you for the answear!
The current version is running on my machine, but later on a server.
Actions the code program does:
When i try to print the full token it does return it correctly. Maybe i am storing the token falsely once i load it from my backend?
I think I found my error, but i don't really know how to fix it I would guess when I try to get the emails I use the standard connection class that this library provides and not my token backend. --> Every time i try to get messages this request is done by the connection class which does the request with its session object.
When the _internal_request() is called the header is always just {}
Fixed it by implementing the _internal_request function inside my own program
My Problem: I have made a program, that gets the number of emails inside an inbox. It also saves and loads the tokens correctly from the token backend, but i get an error, that my request to see the mailbox has no access token.
Help needed: Did I miss a step with authentication or is it not loading my token and the request is send before the token loads? Authentication is True if I have a token stored inside my backend and I do get it when I use test prints. What is wrong?
Error:
My email code:
My token backend code: