Search code examples
pythonalfresco

Alfresco basic authentication works with curl but not with python


I am having a problem with authentication error from Alfresco, maybe somebody could enlighten me while im trying to find log files from the mess that is Alfresco.

curl -uadmin:password -X POST https://hostname/alfresco/api/-default-/public/alfresco/versions/1/nodes/node_uuid/children -F filedata=@/home/user/file.pdf

Now when I am trying to use python requests(TM) it gives me a 401. Ive checked the requests and they both send the same Authentication hash

This is the python code:

def handle_row_for_request(row):

    url = 'https://' + hostname + '/alfresco/api/-default-/public/alfresco/versions/1/nodes/' + base_uuid + '/children'

    data = '/home/user/file.pdf'

    with open(data, 'rb') as payload:
        headers={"content-type": "multipart/form-data"}
        response = requests.post(url, headers=headers, data=payload, auth=(username, password))

Solution

  • You are using the data argument, but you need to use the file argument:

    def handle_row_for_request(row):
    
        url = 'https://' + hostname + '/alfresco/api/-default-/public/alfresco/versions/1/nodes/' + base_uuid + '/children'
    
        files = {'filedata': ('/home/user/file.pdf', open('/home/user/file.pdf', 'rb'))}
        headers={"content-type": "multipart/form-data"}
        response = requests.post(url, headers=headers, files=files, auth=(username, password))