A working example of how to use fileUpload using python

A working example of how to use fileUpload using python

Here's a simple script that you can use to upload a file to zoho using python.  Everything else I've tried kept failing for some reason.  Many thanks to Sergio Basto for creating the module that makes doing this very easy.

Go to https://pypi.python.org/pypi/MultipartPostHandler2/0.1.5 and get the egg file and install it. 

The sample code is as follows.  You can use this to add attachments to contacts as well if you desire.  I haven't tested for Leads module but I'm pretty sure it works fine.  Please note this is a skeleton - no error trapping etc.

import MultipartPostHandler, urllib2

ID ='put the accounts zoho id here '
authtoken = 'your zoho authtoken here'
fileName = "your file name here - i use the full path and filename"

opener = urllib2.build_opener(MultipartPostHandler.MultipartPostHandler)

params = {'authtoken':authtoken,'scope':'crmapi','newFormat':'1','id':ID, 'content':open(fileName,"rb")}

final_URL = " https://crm.zoho.com/crm/private/xml/Accounts/uploadFile"

rslts = opener.open(final_URL, params)

print rslts.read()