Downloading an NTLM / SSPI protected file without prompting for credentials using Python on Win32?

I need to upload a file on a Sharepoint corporate site using CPython. The existing code base does not allow me to use Ironpython without code porting, therefore the .NET WebClient library is missing. I also want to download the file without asking the user to save and without asking the user for network credentials. I tried other libraries, but all of them had a short circuit:

  • urllib2 plus python-ntlm : required to provide user / pass
  • Internet Explorer COM Automation: Requires the user to click the Save button
  • subprocess using wget or cURL : failed to authenticate without user / password request

I could not find anything in pywin32 , it looks like it connects to urllib2 or provides equivalent functionality. So, is there a way to download a file without asking for credentials and without asking the user to click "Save"?

+6
python curl winapi pywin32
source share
1 answer

In the end, I found some VB code from the Microsoft support page that uses the function from urlmon.dll I reproduced it with a single line of ctypes code and it did exactly what I needed.

 ctypes.windll.urlmon.URLDownloadToFileA(0,url,local_file_name,0,0) 
  • url is the location of the resource (in this case, the Excel file on the Sharepoint site).
  • local_file_name is the local path and file name to save.

It transmitted the credentials through a wire without prompts.

+4
source share

All Articles