Skip to content

AttributeError: 'SharePointSession' object has no attribute 'cookie' #69

Description

@hiimani28

`

    authcookie = Office365(base_path, username=username, password=password).GetCookies()
    session = requests.Session()
    session.cookies = authcookie
    session.headers.update({'user-agent': 'python_bite/v1'})
    session.headers.update({'accept': 'application/json;odata=verbose'})
    
    session.headers.update({'X-RequestDigest': 'FormDigestValue'})
    response = session.post(url = base_path + "/sites/" + site_name + "/_api/web/GetFolderByServerRelativeUrl('" + doc_library + "')/Files/add(url='a.txt',overwrite=true)",
                            data="")
    session.headers.update({'X-RequestDigest': response.headers['X-RequestDigest']})
    # perform the actual upload
    with open(file_name_1, 'rb') as file_input:
       
        response = session.post( url = base_path + "/sites/" + site_name + "/_api/web/GetFolderByServerRelativeUrl('" + doc_library + "')/Files/add(url='"+ tail + "',overwrite=true)",data=file_input)
    return True

`

I keep getting the below mentioned error, been stuck on this since 2 days

  • ERROR - upload failed because of 'SharePointSession' object has no attribute 'cookie'
    Traceback (most recent call last):
    File "sharepointTEST.py", line 58, in upload_to_sharepoint
    p = s.post(base_path+"/sites/"+site_name+"/_api/web/folders",
    File "C:\Program Files\Python38\lib\site-packages\sharepy\session.py", line 150, in post
    kwargs["headers"]["Authorization"] = "Bearer " + self._redigest()
    File "C:\Program Files\Python38\lib\site-packages\sharepy\session.py", line 126, in _redigest
    data="", headers={"Cookie": self.cookie})
    AttributeError: 'SharePointSession' object has no attribute 'cookie

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions