← Back to team overview

openerp-india team mailing list archive

[Bug 1002235] [NEW] v6.0.2 UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)

 

Public bug reported:

Hi,
i created a module which put supplier code in the list of suppliers in product, in default_code of the product.
If I put special character like "è" in supplier code, when i try to valid the product, I have this error in client web :

Traceback (most recent call last): File
"/home/gem/instances/602/prod/server/bin/netsvc.py", line 489, in
dispatch result =
ExportService.getService(service_name).dispatch(method, auth, params)
File "/home/gem/instances/602/prod/server/bin/service/web_services.py",
line 599, in dispatch res = fn(db, uid, *params) File
"/home/gem/instances/602/prod/server/bin/osv/osv.py", line 122, in
wrapper return f(self, dbname, *args, **kwargs) File
"/home/gem/instances/602/prod/server/bin/osv/osv.py", line 176, in
execute res = self.execute_cr(cr, uid, obj, method, *args, **kw) File
"/home/gem/instances/602/prod/server/bin/osv/osv.py", line 167, in
execute_cr return getattr(object, method)(cr, uid, *args, **kw) File
"/home/gem/instances/602/prod/server/bin/osv/orm.py", line 2940, in read
result = self._read_flat(cr, user, select, fields, context, load) File
"/home/gem/instances/602/prod/server/bin/osv/orm.py", line 3051, in
_read_flat res2 = self._columns[val[0]].get(cr, self, ids, val, user,
context=context, values=res) File
"/home/gem/instances/602/prod/server/bin/osv/fields.py", line 820, in
get res[r][record] = str(res[r][record]) UnicodeEncodeError: 'ascii'
codec can't encode characters in position 0-3: ordinal not in range(128)

I know this is with server 6.0.2, but the function is the same in 6.0.4
:

actually in server/bin/osv/fields.py line 835 :

if self._type == "integer":
            for r in res.keys():
                # Converting value into string so that it does not affect XML-RPC Limits
                if isinstance(res[r],dict): # To treat integer values with _multi attribute
                    for record in res[r].keys():
                        res[r][record] = str(res[r][record])
                else:
                    res[r] = str(res[r])
        return res

I solved the problem by changing functions used str() by tools.ustr() line 840 :
- res[r][record] = str(res[r][record])
+ res[r][record] = tools.ustr(res[r][record])

I have no contract maintenance, and declare this bug just for information, I no need you correct the code , this is already made for me.
Bye

** Affects: openobject-server
     Importance: Undecided
         Status: New

** Description changed:

  Hi,
  i created a module which put supplier code in the list of suppliers in product, in default_code of the product.
  If I put special character like "è" in supplier code, when i try to valid the product, I have this error in client web :
  
  Traceback (most recent call last): File
  "/home/gem/instances/602/prod/server/bin/netsvc.py", line 489, in
  dispatch result =
  ExportService.getService(service_name).dispatch(method, auth, params)
  File "/home/gem/instances/602/prod/server/bin/service/web_services.py",
  line 599, in dispatch res = fn(db, uid, *params) File
  "/home/gem/instances/602/prod/server/bin/osv/osv.py", line 122, in
  wrapper return f(self, dbname, *args, **kwargs) File
  "/home/gem/instances/602/prod/server/bin/osv/osv.py", line 176, in
  execute res = self.execute_cr(cr, uid, obj, method, *args, **kw) File
  "/home/gem/instances/602/prod/server/bin/osv/osv.py", line 167, in
  execute_cr return getattr(object, method)(cr, uid, *args, **kw) File
  "/home/gem/instances/602/prod/server/bin/osv/orm.py", line 2940, in read
  result = self._read_flat(cr, user, select, fields, context, load) File
  "/home/gem/instances/602/prod/server/bin/osv/orm.py", line 3051, in
  _read_flat res2 = self._columns[val[0]].get(cr, self, ids, val, user,
  context=context, values=res) File
  "/home/gem/instances/602/prod/server/bin/osv/fields.py", line 820, in
  get res[r][record] = str(res[r][record]) UnicodeEncodeError: 'ascii'
  codec can't encode characters in position 0-3: ordinal not in range(128)
  
  I know this is with server 6.0.2, but the function is the same in 6.0.4
  :
  
  actually in server/bin/osv/fields.py line 835 :
  
  if self._type == "integer":
-             for r in res.keys():
-                 # Converting value into string so that it does not affect XML-RPC Limits
-                 if isinstance(res[r],dict): # To treat integer values with _multi attribute
-                     for record in res[r].keys():
-                         res[r][record] = str(res[r][record])
-                 else:
-                     res[r] = str(res[r])
-         return res
+             for r in res.keys():
+                 # Converting value into string so that it does not affect XML-RPC Limits
+                 if isinstance(res[r],dict): # To treat integer values with _multi attribute
+                     for record in res[r].keys():
+                         res[r][record] = str(res[r][record])
+                 else:
+                     res[r] = str(res[r])
+         return res
  
- I solved the problem by changing functions used str() by tools.ustr()
- line 840.
+ I solved the problem by changing functions used str() by tools.ustr() line 840 :
+ - res[r][record] = str(res[r][record])
+ + res[r][record] = tools.ustr(res[r][record])
  
  I have no contract maintenance, and declare this bug just for information, I no need you correct the code , this is already made for me.
  Bye

-- 
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Server.
https://bugs.launchpad.net/bugs/1002235

Title:
  v6.0.2 UnicodeEncodeError: 'ascii' codec can't encode characters in
  position 0-3: ordinal not in range(128)

Status in OpenERP Server:
  New

Bug description:
  Hi,
  i created a module which put supplier code in the list of suppliers in product, in default_code of the product.
  If I put special character like "è" in supplier code, when i try to valid the product, I have this error in client web :

  Traceback (most recent call last): File
  "/home/gem/instances/602/prod/server/bin/netsvc.py", line 489, in
  dispatch result =
  ExportService.getService(service_name).dispatch(method, auth, params)
  File
  "/home/gem/instances/602/prod/server/bin/service/web_services.py",
  line 599, in dispatch res = fn(db, uid, *params) File
  "/home/gem/instances/602/prod/server/bin/osv/osv.py", line 122, in
  wrapper return f(self, dbname, *args, **kwargs) File
  "/home/gem/instances/602/prod/server/bin/osv/osv.py", line 176, in
  execute res = self.execute_cr(cr, uid, obj, method, *args, **kw) File
  "/home/gem/instances/602/prod/server/bin/osv/osv.py", line 167, in
  execute_cr return getattr(object, method)(cr, uid, *args, **kw) File
  "/home/gem/instances/602/prod/server/bin/osv/orm.py", line 2940, in
  read result = self._read_flat(cr, user, select, fields, context, load)
  File "/home/gem/instances/602/prod/server/bin/osv/orm.py", line 3051,
  in _read_flat res2 = self._columns[val[0]].get(cr, self, ids, val,
  user, context=context, values=res) File
  "/home/gem/instances/602/prod/server/bin/osv/fields.py", line 820, in
  get res[r][record] = str(res[r][record]) UnicodeEncodeError: 'ascii'
  codec can't encode characters in position 0-3: ordinal not in
  range(128)

  I know this is with server 6.0.2, but the function is the same in
  6.0.4 :

  actually in server/bin/osv/fields.py line 835 :

  if self._type == "integer":
              for r in res.keys():
                  # Converting value into string so that it does not affect XML-RPC Limits
                  if isinstance(res[r],dict): # To treat integer values with _multi attribute
                      for record in res[r].keys():
                          res[r][record] = str(res[r][record])
                  else:
                      res[r] = str(res[r])
          return res

  I solved the problem by changing functions used str() by tools.ustr() line 840 :
  - res[r][record] = str(res[r][record])
  + res[r][record] = tools.ustr(res[r][record])

  I have no contract maintenance, and declare this bug just for information, I no need you correct the code , this is already made for me.
  Bye

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-server/+bug/1002235/+subscriptions


Follow ups

References