Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

[Odoo 11.0, Python 3]Save Images with base64 encoding

Naroči se

Get notified when there's activity on this post

This question has been flagged
base64python3odoo11.0
1 Odgovori
33622 Prikazi
Avatar
Ermin Trevisan

I'm still working on porting the module https://www.odoo.com/apps/modules/10.0/product_default_image/ to Odoo 11.0.

When trying to save an PNG image with the following code in the file rescompany.py:

@api.model
def _get_default_image(self):
with open(modules.get_module_resource('product_default_image',
'static/src/img',
'glob_prod_img.png'),
'rb') as f:
return base64.b64encode(f.read())

product_image = fields.Binary(
string='Global Product Image',
default=_get_default_image,
help='Use as the global image for all product default images. '
'Limited to 1024x1024.',
)


@api.multi
def write(self, vals):
""" Changes product images if target or product_image have changed """

target = vals.get('product_image_target')

if 'product_image' not in vals and not target:
return super(ResCompany, self).write(vals)

if 'product_image' in vals:
vals['product_image'] = \
tools.image_resize_image_big(
base64_source=vals['product_image'],
)

I get the following error message:

Error:
Odoo Server Error

Traceback (most recent call last):
File "/usr/lib/python3.6/base64.py", line 510, in _input_type_check
m = memoryview(s)
TypeError: memoryview: a bytes-like object is required, not 'str'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/lib/python3.6/encodings/base64_codec.py", line 19, in base64_decode
return (base64.decodebytes(input), len(input))
File "/usr/lib/python3.6/base64.py", line 545, in decodebytes
_input_type_check(s)
File "/usr/lib/python3.6/base64.py", line 513, in _input_type_check
raise TypeError(msg) from err
TypeError: expected bytes-like object, not str

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/http.py", line 653, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 312, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/usr/lib/python3/dist-packages/odoo/tools/pycompat.py", line 87, in reraise
raise value
File "/usr/lib/python3/dist-packages/odoo/http.py", line 695, in dispatch
result = self._call_function(**self.params)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 344, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 337, in checked_call
result = self.endpoint(*a, **kw)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 939, in __call__
return self.method(*args, **kw)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 517, in response_wrap
response = f(*args, **kw)
File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 934, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 926, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/api.py", line 687, in call_kw
return call_kw_model(method, model, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/api.py", line 672, in call_kw_model
result = method(recs, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/addons/account/models/res_config_settings.py", line 152, in create
return super(ResConfigSettings, self).create(values)
File "/usr/lib/python3/dist-packages/odoo/models.py", line 3402, in create
self._fields[key].determine_inverse(record)
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1082, in determine_inverse
self.inverse(records)
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 599, in _inverse_related
other[field.name] = record_value[record]
File "/usr/lib/python3/dist-packages/odoo/models.py", line 4794, in __setitem__
return self._fields[key].__set__(self, value)
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 987, in __set__
record.write({self.name: write_value})
File "/usr/lib/python3/dist-packages/odoo/addons/product_default_image/models/res_company.py", line 76, in write
base64_source=vals['product_image'],
File "/usr/lib/python3/dist-packages/odoo/tools/image.py", line 143, in image_resize_image_big
return image_resize_image(base64_source, size, encoding, filetype, avoid_if_small)
File "/usr/lib/python3/dist-packages/odoo/tools/image.py", line 56, in image_resize_image
image_stream = io.BytesIO(codecs.decode(base64_source, encoding))
TypeError: decoding with 'base64' codec failed (TypeError: expected bytes-like object, not str)

How do I correctly code this for Python3/Odoo 11?

Thanks for any hints.




-1
Avatar
Opusti
Avatar
Rajkumar
Best Answer

Hi,

Refer this link

https://stackoverflow.com/questions/2323128/convert-string-in-base64-to-image-and-save-on-filesystem-in-python

​


2
Avatar
Opusti
Ermin Trevisan
Avtor

Thank you for your hint, I understand the direction, but why is it no handled by the tools from image.py in Odoo 11? I have amended my code in the post. Is there something missing in my @api.model?

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

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
make my function work forever
python3 odoo11.0
Avatar
Avatar
1
jan. 20
3719
add python function to specific action
python3 odoo11.0
Avatar
0
jan. 20
4015
valid logged in user
python3 odoo11.0
Avatar
Avatar
1
dec. 19
4807
Add dynamic domain to allocation leave type
onchange python3 odoo11.0
Avatar
Avatar
1
maj 24
3761
Hide fields in Filters And Group By Solved
python3 odoo11.0 Jquery
Avatar
Avatar
Avatar
3
jun. 23
17092
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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