我使用 python 瓶创建了一个用于访问 OpenERP REST API 的 api。
我的问题是在上传图像文件并将其写入 OpenERP 中的二进制字段时
它抛出 raise TypeError,“除非启用 allow_none,否则无法编组 None”
在这里我上传了我的代码
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)