Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

Import image with Odoo API

Odoberať

Get notified when there's activity on this post

This question has been flagged
imageapiodoo
1 Odpoveď
11148 Zobrazenia
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
Zrušiť
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
Zrušiť
Enjoying the discussion? Don't just read, join in!

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

Registrácia
Related Posts Replies Zobrazenia Aktivita
Odoo Session Expired Error When Accessing API Endpoint
api odoo
Avatar
Avatar
2
dec 24
3477
How to set image upload size?
image odoo
Avatar
Avatar
1
jan 23
3461
How to get data with rest API and post it in odoo view? Solved
api odoo
Avatar
Avatar
1
feb 22
4863
Create a module , with CRUD operation using external API
api odoo
Avatar
Avatar
1
feb 22
7981
Possible to create contact through API call?
api odoo
Avatar
0
nov 21
5478
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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