r/learnpython • • 14d ago

How upload files to SPO in Nov 2026, Authorization updates

Hi all, I'm trying to use Python to upload multiple files posted SPO.

Tried this code for Auth and failed, for my case error says need to use client_id which I believe = EntraID? For this I think I need to contact somebody with proper rights.

I afraid that modern MS Security is faster then Python libs, is anybody is running this code successfully in Nov 2026? Surely I will try to set all configuration values rights.

Or can you recommend other approach. Thansk to all

from office365.runtime.auth.user_credentials import UserCredential
from office365.sharepoint.client_context  import ClientContext

# 1. Configuration                        
site_url = r"https://asratomkaX.sharepoint.com"
teenant = 'asratomkaX'
client_id = '123456' # <===????? ke paso ?
username = r'user@myorg.org'
password = r'welcommen1'
 
# Use with_username_and_password(tenant, client_id, username, password) instead.  For on-premises SharePoint, use allow_ntlm=True.

# 2. Authenticate
#ctx = ClientContext(site_url).with_credentials(UserCredential(username, password))
ctx = ClientContext(site_url)
ctx.with_username_and_password( teenant,client_id, username, password)


s: 400, Error: Traceback (most recent call last):
File "C:\Users\mocado\PyCharmMiscProject\.venv\Lib\site-packages\msal\authority.py", line 98, in __init__
openid_config = tenant_discovery(
tenant_discovery_endpoint,
self._http_client)
File "C:\Users\mocado\PyCharmMiscProject\.venv\Lib\site-packages\msal\authority.py", line 298, in tenant_discovery
raise ValueError("OIDC Discovery failed on {}. HTTP status: {}, Error: {}".format(
...<3 lines>...
))
ValueError: OIDC Discovery failed on https://login.microsoftonline.com/mocado/v2.0/.well-known/openid-configuration. HTTP statu
1 Upvotes

4 comments sorted by

1

u/danielroseman 13d ago

You'd probably get more answers to this if you explained what SPO is. And if you showed the full traceback including which line in your code caused the error.

1

u/RaidZ3ro 13d ago

There's many layers to this.. I suggest you contact your SharePoint Admin to assist here asap because you'll need a bunch of help looking at what you have right now...

1

u/Discordbothost 13d ago

the client_id it wants is the Application (client) ID of an app registration in Entra, not anything about your user. and username/password auth tends to get blocked anyway once the tenant enforces MFA, which most do now, so even with the right id it may keep failing.

the route that keeps working is an app registration with a certificate:

ctx = ClientContext(site_url).with_client_certificate(tenant, client_id, thumbprint=thumb, cert_path="cert.pem")

you can't create that yourself without rights though, an admin has to register the app and grant it Sites.Selected for your site. so yeah, the sharepoint admin is the first stop. (and if that password in the post is real, change it)