3

I'm trying to post a request with authentication.

This works for a get request:

import win32com.client
h = win32com.client.Dispatch('WinHTTP.WinHTTPRequest.5.1')
h.SetAutoLogonPolicy(0)
h.Open('GET', url, False)
h.Send()

But I'm trying to make a post request, in particular, form-data, with file

data = {'datasetid': 9,
        'date':"2018-04-16",
        'file':open(r'C:\filename.pdf', 'rb').read()}
h = win32com.client.Dispatch('WinHTTP.WinHTTPRequest.5.1')
h.SetAutoLogonPolicy(0)
h.Open('POST', url, False)
h.SetRequestHeader('Content-Type', 'multipart/form-data')
h.Send(json.dumps(data))

This don't work because 'bytes' is not JSON serializable. Changing 'rb' to 'r' don't work because 'charmap' codec can't decode byte 0x9d in position 143.

How do I send a file over? (And send the Authentication thing over as well, we are using NT Authentication).

I have tried using requests_ntlm and that works. But I would like to find a method that does not require to key in the authentication. using requests_ntlm, I need to key in something like session.auth = HttpNtlmAuth('username','password').

I'm looking for a solution like win32com SetAutoLogonPolicy(0) so that there is no need to key in username and password.

Lim Min
  • 41
  • 4

1 Answers1

0

https://github.com/brandond/requests-negotiate-sspi

works for the autologon and requests.post as usual. But but, still wondering how h.Send() works for files. :)

Lim Min
  • 41
  • 4