Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

Import image with Odoo API

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
imageapiodoo
1 Răspunde
10973 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
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

Imagine profil
shreeram
Cel mai bun răspuns

   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
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

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

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
Odoo Session Expired Error When Accessing API Endpoint
api odoo
Imagine profil
Imagine profil
2
dec. 24
3235
How to set image upload size?
image odoo
Imagine profil
Imagine profil
1
ian. 23
3324
How to get data with rest API and post it in odoo view? Rezolvat
api odoo
Imagine profil
Imagine profil
1
feb. 22
4721
Create a module , with CRUD operation using external API
api odoo
Imagine profil
Imagine profil
1
feb. 22
7844
Possible to create contact through API call?
api odoo
Imagine profil
0
nov. 21
5289
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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