Reputation: 800
I created an api using python bottle for accessing OpenERP REST API.
My problem is while uploading a image file and writing it into the binary field in OpenERP
it throws raise TypeError, "cannot marshal None unless allow_none is enabled"
Here I uploaded my code
from bottle import get, post, run,request,error,route,template
@route('/')
def index():
return'''Welcome'''
@error(500)
def custom500(error):
return 'Error while validating data.'
# Advisor Creation Start #
@get('/advisor') # or @route('/advisor')
def advisor_form():
form ='''<form method="POST" action="/advisor" enctype="multipart/form-data">
Photo:<input name="photo" type="file"/><br>
<input type="submit" />
</form>'''
return form
@post('/advisor') # or @route('/advisor', method='POST')
def advisor_submit():
import xmlrpclib
username = 'uname'
pwd = 'pwd'
dbname = 'db'
photo = request.files.get('photo')
print photo,"L:K<:L"
sock_common = xmlrpclib.ServerProxy ('http://localhost:8069/xmlrpc/common')
try:
uid = sock_common.login(dbname, username, pwd)
except("Error username or password"):
print "sock_common error"
sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
res={
'consultant_photo':photo
}
advisor_id = sock.execute(dbname, uid, pwd, 'res.advisor', 'create', res)
return 'Advisor Created!'
# Advisor Creation End #
run(host='localhost', port=8000)
Upvotes: 1
Views: 4305
Reputation: 416
This are the things you have to do before the uploaded file is ready to send to OpenERP
get the file pointer
photo = request.files.get('photo')
read the file data
photo_data = photo.file.read()
encode with base64
base64.b64encode(photo_data)
Now you can pass this data to openerp
Upvotes: 3