Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Import image with Odoo API

Subscriure's

Get notified when there's activity on this post

This question has been flagged
imageapiodoo
1 Respondre
10969 Vistes
Avatar
Yves Bourgois

Hi Guys,

I'm working on a script to import a list of product in my Odoo database. The script is working really fine with the Odoo API, except for importing the image.
What I have done so far, is to import an image from an URL in python, and then, encoding it in base64: 

        response = requests.get(image_url)
img_obj = Image.open(BytesIO(response.content))
buffer = BytesIO()
img_obj.save(buffer, format="JPEG")
img = base64.encodestring(buffer.getvalue()).strip()
try:
base64.b64decode(img)
except TypeError:
padding = len(img) % 4
if padding == 1:
img = "Invalid base64 string: {}".format(img)
elif padding == 2:
img += b'=='
elif padding == 3:
img += b'='

This code is working great. But, when I run the python code to import it with Odoo API, here is what I have:
mlrpc.client.Fault: <Fault 1: 'Traceback (most recent call last):\n File "/opt/odoo/openerp/service/wsgi_server.py", line 56, in xmlrpc_return\n result = openerp.http.dispatch_rpc(service, method, params)\n File "/opt/odoo/openerp/http.py", line 114, in dispatch_rpc\n result = dispatch(method, params)\n File "/opt/odoo/openerp/service/model.py", line 37, in dispatch\n res = fn(db, uid, *params)\n File "/opt/odoo/openerp/service/model.py", line 173, in execute_kw\n return execute(db, uid, obj, method, *args, **kw or {})\n File "/opt/odoo/openerp/service/model.py", line 118, in wrapper\n return f(dbname, *args, **kwargs)\n File "/opt/odoo/openerp/service/model.py", line 181, in execute\n res = execute_cr(cr, uid, obj, method, *args, **kw)\n File "/opt/odoo/openerp/service/model.py", line 170, in execute_cr\n return getattr(object, method)(cr, uid, *args, **kw)\n File "/opt/odoo/openerp/api.py", line 238, in wrapper\n return old_api(self, *args, **kwargs)\n File "/opt/odoo/addons/stock/product.py", line 518, in write\n return super(product_template, self).write(cr, uid, ids, vals, context=context)\n File "/opt/odoo/openerp/api.py", line 238, in wrapper\n return old_api(self, *args, **kwargs)\n File "/opt/odoo/openerp/api.py", line 369, in old_api\n result = method(recs, *args, **kwargs)\n File "/opt/odoo/addons/account/models/product.py", line 45, in write\n res = super(ProductTemplate, self).write(vals)\n File "/opt/odoo/openerp/api.py", line 236, in wrapper\n return new_api(self, *args, **kwargs)\n File "/opt/odoo/openerp/api.py", line 562, in new_api\n result = method(self._model, cr, uid, self.ids, *args, **old_kwargs)\n File "/opt/odoo/addons/product/product.py", line 705, in write\n res = super(product_template, self).write(cr, uid, ids, vals, context=context)\n File "/opt/odoo/openerp/api.py", line 238, in wrapper\n return old_api(self, *args, **kwargs)\n File "/opt/odoo/openerp/api.py", line 369, in old_api\n result = method(recs, *args, **kwargs)\n File "/opt/odoo/addons/mail/models/mail_thread.py", line 274, in write\n result = super(MailThread, self).write(values)\n File "/opt/odoo/openerp/api.py", line 236, in wrapper\n return new_api(self, *args, **kwargs)\n File "/opt/odoo/openerp/models.py", line 3820, in write\n self._write(old_vals)\n File "/opt/odoo/openerp/api.py", line 236, in wrapper\n return new_api(self, *args, **kwargs)\n File "/opt/odoo/openerp/api.py", line 562, in new_api\n result = method(self._model, cr, uid, self.ids, *args, **old_kwargs)\n File "/opt/odoo/openerp/models.py", line 3971, in _write\n result += self._columns[field].set(cr, self, id, field, vals[field], user, context=rel_context) or []\n File "/opt/odoo/openerp/osv/fields.py", line 646, in set\n \'datas\': value,\n File "/opt/odoo/openerp/api.py", line 236, in wrapper\n return new_api(self, *args, **kwargs)\n File "/opt/odoo/openerp/api.py", line 478, in new_api\n result = method(self._model, cr, uid, *args, **old_kwargs)\n File "/opt/odoo/openerp/addons/base/ir/ir_attachment.py", line 459, in create\n values[\'mimetype\'] = self._compute_mimetype(values)\n File "/opt/odoo/openerp/addons/base/ir/ir_attachment.py", line 252, in _compute_mimetype\n mimetype = guess_mimetype(values[\'datas\'].decode(\'base64\'))\n File "/usr/lib/python2.7/xmlrpclib.py", line 503, in decode\n self.data = base64.decodestring(data)\n File "/usr/lib/python2.7/base64.py", line 321, in decodestring\n return binascii.a2b_base64(s)\nError: Incorrect padding\n'>

I have tried to correct the base64 padding, (as you can see in my previous code), but that's not working. Did anyone know how can I fixe this problem?

Thanks,

Don

0
Avatar
Descartar
Cybrosys Techno Solutions Pvt.Ltd

Try refer the following forum post
https://www.odoo.com/sl_SI/forum/help-1/how-to-import-image-from-api-159947

Avatar
shreeram
Best Answer

   path = 'logo1.png'

   # get file

   with open(path, 'rb') as f:

        contents = f.read()

   imageBase64 = base64.b64encode(contents) #convert to base64

   imageBase64.decode() #pass the value of this decode result


Mail me for any question: shreeramyadav1993@gmail.com

1
Avatar
Descartar
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
Odoo Session Expired Error When Accessing API Endpoint
api odoo
Avatar
Avatar
2
de des. 24
3233
How to set image upload size?
image odoo
Avatar
Avatar
1
de gen. 23
3323
How to get data with rest API and post it in odoo view? Solved
api odoo
Avatar
Avatar
1
de febr. 22
4721
Create a module , with CRUD operation using external API
api odoo
Avatar
Avatar
1
de febr. 22
7843
Possible to create contact through API call?
api odoo
Avatar
0
de nov. 21
5286
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now