Python Requests: Connect to Sharepoint online with 2-factor auth enabled - python

I would like to create a Python script to retrieve lists from Sharepoint Online and potentially update them. I can do all of this from the browser just fine. However, I'm having a hard time connecting to Sharepoint using the Requests module. When I navigate to https://mysharepoint.sharepoint.com, I get redirected to the https://login.microsoftonline.com to log in through my account. The login mechanism also requires two-factor authentication.
I'm not sure whether there's a way I could log in using Python at all at this point. Most of the packages I've tried have not been able to authenticate my user.

Related

How to connect to sharepoint from a python script after Microsoft deprecates basic authentication and forces MFA?

I currently have a script in python using shareplum library which connects to our sharepoint to upload a specific file periodically. Currenly it's authenticating via an app password.
Recently I just saw this Microsoft notice that they will disable basic authentication including app passwords and they will be forcing MFA from 03/31/2023.
I've been looking for alternatives to keep using this kind of automated scripts to work with sharepoint files but I couldn't find anything...
What do you suggest?

Is there another mode to work SharePoint and python without using share plum?

I I want to upload to local sharepoint without using shareplum package, is there another package for this?
I am having problem authenticating my credentials in sharepoint and python using shareplum, the error generated and the 401. So I want to see the possibility of trying another package.

Sharepoint api functions execute via python module through proxied communication

Has anyone tried to execute a sharepoint function via python module through a proxy? I’ve tried to use shareplum and other python modules to execute the sharepoint calls, but run into an issue with the tls version not being valid or ssl error. I’ve tried setting the tls version, but still get an invalid version for the ssl or the tls version depending. I know I’m able to access the proxy, but fail to access the sharepoint site with a bad authentication.
I can access other sites via request, but I know that I need shareplum or something similar to execute the sharepoint site functions. If not going through a proxy, then I have no issue. However, my company recently deployed a proxy and now my script is no longer working. The code to use shareplum is similar to the code provide by the git project. However, the git project assumes straightforward communication to the web server with https or http
I’ve tried changing the tls version to default 1.1 and 1.2, but neither work. I’ve also tried setting the protocol to http verses https and tried to first pass the proxy server, but no success. I tried using proxy manager using the proxy, then using the created session to access the sharepoint site, but that also fails. Using the proxy manager caused a bad authentication with the sharepoint site.

Authenticate to JIRA with gmail in python

I am trying to authenticate to jira by google sign-in using a python script . I am using jira python library.
I tried using basic_auth but it failed with error as my account is registered through gmail.
jira=JIRA(options,basic_auth=(values['USERNAME'],values['PASSWORD']));
When you first logged in as a Google user to the system, you would have been prompted to create an "OnDemand" password, used for things like Subversion or authenticated RSS feed access. This is the password you will need to use when using the JIRA API.
If you can't remember this password, please see: https://confluence.atlassian.com/display/AOD/Changing+Your+Password+in+Atlassian+OnDemand
Source

Downloading a File Protected by NTLM/SSPI Without Prompting For Credentials Using Python on Win32?

I need to download a file on a corporate Sharepoint site using CPython. Existing codebase prevents me from using Ironpython without porting the code, so .NET's WebClient library is out. I also want to download the file without prompting the user to save and without prompting the user for network credentials. I tried other libraries, but they all had short-comings:
urllib2 plus python-ntlm: requires user/pass to be provided
COM automation of Internet Explorer: requires the user to click 'Save'
subprocess using wget or cURL: couldn't get either to authenticate without requesting user/pass
I couldn't find anything in pywin32 that looks like it hooks into urllib2 or provides equivalent functionality. So, is there a way to download the file without requesting credentials and without prompting the user to click 'Save'?
I ended up finding some VB code from a Microsoft support page that uses a function from urlmon.dll I replicated it with a single line of ctypes code and it accomplished exactly what I needed it to do.
ctypes.windll.urlmon.URLDownloadToFileA(0,url,local_file_name,0,0)
url is the location of the resource (in this case, an Excel file on a Sharepoint site)
local_file_name is the local path and name of the file to be saved.
This passed credentials across the wire with no prompts.

Categories