Tuesday, November 27, 2012

pyodbc utf-8

Hello community
 
i have a next problem. i have connected with pyodbc to a mssql db. i read values out of it, all works, but i have problems with "ä" "ö" and "ü".
on my html.page i made this into the header:
 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 
on all my pages this umlauts works, but not the values of the pyodbc...
when i only give out the row, i become something like this: Hansj\xf6rg ,but it have to be this: Hansjörg
when i print this value out into a table, the field keeps empty.
 
it must be a problem of pyodbc, but i dont know how to fix it. i tryed something like this:
 
views.py --------------------------------------------------------
def kundendaten(request):
    ret = request.POST
    form = ret['kunde']
    conn = pyodbc.connect('DRIVER={SQL Server};SERVER=MAURITIUS;DATABASE=baan5c;UID=portal;PWD=P0rtalReader')
    cursor = conn.cursor()
    cursor.execute("SELECT x.t_name, x.t_user, y.t_mail FROM tttaad200000 as x, tttcmf200000 as y WHERE (x.t_name = y.t_name) AND (x.t_user = '%s')"%form)
    rows = unicode(cursor.fetchall(), 'utf-8')
    now = datetime.datetime.now()
    return render_to_response("kundendaten.html", { 'rows': rows, 'current_date': now, 'form': form}, context_instance=RequestContext(request))
---------------------------------------------------------------------
but the page gave this error:

TypeError at /kundendaten/

coercing to Unicode: need string or buffer, list found
 
i dont know how i can fix my problem... what i use:
win7 32bit
python 2.7
django 1.4.1
pyodbc 3.0.6
 
can someone halp me to fix this problem?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/mu-OphC5QjcJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment