File uploaded to salesforce empty using python and simple_salesforce
Question: I'm trying to upload a file to the Folder object in salesforce using python
and simple_salesforce. The file is uploaded but is empty. can anyone tell me
why and how to fix the problem? Thanks.

    
    
    import base64
    import json
    from simple_salesforce import Salesforce
    
    userName = 'username'
    passWord = 'password'
    securitytoken = 'securitytoken'
    
    sf=Salesforce(username='userName', password='passWord', security_token='securitytoken', sandbox = True)
    sessionId = sf.session_id
    
    body = ""
    with open("Info.txt", "r") as f:
        body = base64.b64encode(f.read())
    
    response = requests.post('https://cs17.my.salesforce.com/services/data/v23.0/sobjects/Document/',
    headers = { 'Content-type': 'application/json', 'Authorization':'Bearer %s' % sessionId},
    data = json.dumps({
        'Description':'Information',
        'Keywords':'Information',
        'FolderId': '00lg0000000MQykAAG',
        'Name': 'Info',
        'Type':'txt'
        })
    )
    
    print response.text
    


Answer: Based on the code above, your request is incomplete. You create the body value
as the b64encoding iof the file you wish to upload, but it isn't included in
your data associated with a 'body' key.

Depending on your version of json, you may experience some problems getting
the output to play nice with Salesforce. I switched from json to simplejson
and that worked better for me.

