Git Product home page Git Product logo

tds-django's People

Contributors

ecogels avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

cnanyi

tds-django's Issues

error with encoding gb18030

I use django 3.2.10 with tsd-django driver, the table data in Sqlserver2017 is wrong value:
id: 1, name: '常'

this is the Traceback in django admin:

Unicode error hint
The string that could not be encoded/decoded was: ����


Traceback (most recent call last):
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/django/contrib/admin/options.py", line 616, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/django/contrib/admin/sites.py", line 232, in inner
    return view(request, *args, **kwargs)
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/django/utils/decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/django/contrib/admin/options.py", line 1815, in changelist_view
    'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)},
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/django/db/models/query.py", line 262, in __len__
    self._fetch_all()
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/django/db/models/query.py", line 1324, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/django/db/models/query.py", line 51, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1208, in execute_sql
    return list(result)
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1646, in cursor_iter
    for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel):
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1646, in <lambda>
    for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel):
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/django/db/utils.py", line 97, in inner
    return func(*args, **kwargs)
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/pytds/__init__.py", line 868, in fetchmany
    row = self.fetchone()
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/pytds/__init__.py", line 853, in fetchone
    row = self._session.fetchone()
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/pytds/tds.py", line 1581, in fetchone
    if not self.next_row():
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/pytds/tds.py", line 1592, in next_row
    self.process_token(marker)
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/pytds/tds.py", line 1542, in process_token
    return handler(self)
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/pytds/tds.py", line 1660, in <lambda>
    tds_base.TDS_NBC_ROW_TOKEN: lambda self: self.process_nbcrow(),
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/pytds/tds.py", line 663, in process_nbcrow
    value = curcol.serializer.read(r)
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/pytds/tds_types.py", line 690, in read
    return r.read_str(size, self._codec)
  File "/Users/anyi/.local/share/virtualenvs/myapp/lib/python3.9/site-packages/pytds/tds.py", line 212, in read_str
    return codec.decode(readall(self, size))[0]

Exception Type: UnicodeDecodeError at /admin/users/archive/
Exception Value: 'gbk' codec can't decode byte 0xfc in position 2: illegal multibyte sequence

the byte code of name is:

b'\xb3\xa3\xfc\xc7'

it can be decode as gb18030

>>> b'\xb3\xa3\xfc\xc7'.decode('gb18030')
'常\ue3d2'

so, I use pymssql fetch the same record, the return values:

...
>>>row = cur.fetchone()
>>>row[0], row[1]:
>>>1, '常\ue3d2'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.