Python Forum
I need help trying to access an email box using msal
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need help trying to access an email box using msal
#1
I am fairly new to python. I have been working on this for a few weeks. A previous employee used basic authentication to access email on our exchange server. According to Microsoft this is going away October 1st. I am working on using modern authentication, and am having no luck. I have looked through Microsoft's documentation on this, and it did not help. I have searched the web, to no avail. I am able to get an access token, but when I try to access the email box I get a 400 response instead of 200. Below is the code snippet that appears to be the problem, and the code I use to get the access token, incase that helps. The ConfidentialClientApplication actually does have the proper data, and the <user> is the actual username.


app = ConfidentialClientApplication(
        "",
        authority="",
        client_credential=""
        )

result = None
result = app.acquire_token_silent(["https://graph.microsoft.com/.default"], account=None)

if not result:
    result = app.acquire_token_for_client(scopes="https://graph.microsoft.com/.default")

if "access_token" in result:
    print(result["token_type"])
else:
    print(result.get("error"))
    print(result.get("error_description"))
    print(result.get("correlation_id"))  # You might need this when reporting a bug.

print(result["access_token"])
headers = {
    'Authorization': 'Bearer ' + result["access_token"]
}

# Step 2. Retrieve emails

response = requests.get('https://graph.microsoft.com/v1.0/users/<user>/mailFolder/inbox/messages', headers=headers)

print(response.json())
if response.status_code != 200:
    raise Exception(response.json())
The error that I am receiving is below.

'error': {'code': 'Request_BadRequest', 'message': 'Unexpected segment DynamicPathSegment. Expected property/$value.'


I would greatly appreciate any help, or even some sort of clear documentation or examples that you could provide.
Thank you for taking the time to read this.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  An email with inline jpg cannot be read by all email clients fpiraneo 4 4,012 Feb-25-2018, 07:17 PM
Last Post: fpiraneo
  Email - Send email using Windows Live Mail cyberzen 2 5,945 Apr-13-2017, 03:14 AM
Last Post: cyberzen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020