title: Python O365 Outlook Connection Issues
body: <p>I am trying to write a script in Python to grab new emails from a specific folder and save the attachments to a shared drive to upload to a database. Power Automate would work, but the file size limit to save the attachment is a meager 20 MB. I am able to authenticate the token, but am getting the following error when trying to grab the emails:</p>
  <p>Unauthorized for url.
  The token contains no permissions, or permissions can not be understood.</p>
  <p>I have included the code I am using to connect to Microsoft Graph.</p>
  <p>(credentials and tenant_id are correct in my code, took them out for obvious reasons</p>
  <pre><code>from O365 import Account, MSOffice365Protocol, MSGraphProtocol
  
  credentials = ('xxxxxx', 'xxxxxx')  
  protocol = MSGraphProtocol(default_resource='reporting.triometric@xxxx.com')  
  scopes_graph = protocol.get_scopes_for('message_all_shared')  
  scopes = ['https://graph.microsoft.com/.default']  
  account = Account(credentials, auth_flow_type='credentials', tenant_id=&quot;**&quot;, scopes=scopes,)  
  
  
  if account.authenticate():  
  print('Authenticated')  
  mailbox = account.mailbox(resource='reporting.triometric@xxxx.com')  
  inbox = mailbox.inbox_folder()  
  for message in inbox.get_messages():  
  print(message)  
  </code></pre>
  <p>I have already configured the permissions through Azure to include all the necessary 'mail' delegations.</p>
  <p>The rest of my script works perfectly fine for uploading files to the database. Currently, the attachments must be manually saved on a shared drive multiple times per day, then the script is run to upload. Are there any steps I am missing? Any insights would be greatly appreciated!</p>
  <p>Here are the permissions:<a href="https://i.stack.imgur.com/eZ5Z6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eZ5Z6.png" alt="enter image description here" /></a></p>