0

I have taken the following code from other post. This is very good and working fine.

import requests
from requests_ntlm import HttpNtlmAuth
session = requests.Session()
session.auth = HttpNtlmAuth('DOMAIN\\username','password', session)

put_url = 'https://secure.sp.kp.org/teams/scpmgcc/complete%20care/Proactive%20Care/POE_CCTE_TAT/2017%20Reports'
with open('p:/ccte/_ccte_tat_template.xls','rb') as fin:
    myFile = requests.put('{}/_ccte_tat_template.xls'.format(put_url), 
                          data=fin.read(), 
                          auth=session.auth, 
                          headers={'content-type':'application/vnd.ms-excel'})

The file is uploaded fine with checked out status. Please let me know how we can check in the file when uploading using the same above code.

I tried with different options :

my_headers = {
            'accept' : 'application/json;odata=verbose',
            'content-type' : 'application/json;odata=verbose',
            'odata' : 'verbose',
            'X-RequestForceAuthentication' : 'true'
        }

Tried like below as well.

 import requests
    from requests_ntlm import HttpNtlmAuth
    session = requests.Session()
    session.auth = HttpNtlmAuth('DOMAIN\\username','password', session)

  my_headers = {
                'accept' : 'application/vnd.ms-excel;odata=verbose',
                'content-type' : 'application/vnd.ms-excel;odata=verbose',
                'odata' : 'verbose',
                'X-RequestForceAuthentication' : 'true',
                'Connection': 'close'
            }


    put_url = 'https://secure.sp.kp.org/teams/scpmgcc/complete%20care/Proactive%20Care/POE_CCTE_TAT/2017%20Reports'
    with open('p:/ccte/_ccte_tat_template.xls','rb') as fin:
        myFile = requests.put('{}/_ccte_tat_template.xls'.format(put_url), 
                              data=fin.read(), 
                              auth=session.auth, 
                              headers=my_headers)

Nothing is working. Any one has any idea how to fix this issue

1

1 Answer 1

0

If it's an option, you can go to Library Settings -> Versioning Settings and turn off Require documents to be checked out before editing, after which new files uploaded will not be checked out by default.

If that's not an option, I don't know python, but the general format for a REST call to check in a file looks like this:

POST https://{site_url}/_api/web/GetFileByServerRelativeUrl('/Folder Name/{file_name}')/CheckIn(comment='Comment',checkintype=0)
X-RequestDigest: "{form_digest_value}"

Ref: Working with folders and files with REST

1
  • Thanks Joe.I know the first option. If we disable that checkout requirements will be turned off for existing files as well. For The second one getting 404 error.
    – mssr
    Feb 24, 2020 at 23:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.