Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7683395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:46:55+00:00 2026-05-31T18:46:55+00:00

Python novice here. I am using python2.7.2 on Windows7. I have installed the PyWin32

  • 0

Python novice here.

I am using python2.7.2 on Windows7.

I have installed the PyWin32 extensions (build 217).

I have adopdbapi installed in c:\Python27\Lib\site-packages\adodbapi

I have a very simple module that queries the AdventureWorks2008LT database in MS SQL Server.

import adodbapi

connStr='Provider=SQLOLEDB.1;' \
    'Integrated Security=SSPI;' \
    'Persist Security Info=False;' \
    'Initial Catalog=AVWKS2008LT;' \
    'Data Source=.\\SQLEXPRESS'

conn = adodbapi.connect(connStr)

tablename = "[salesLT].[Customer]"

# create a cursor
cur = conn.cursor()

# extract all the data
sql = "select * from %s" % tablename
cur.execute(sql)

# show the result
result = cur.fetchall()
for item in result:
    print item

# close the cursor and connection
cur.close()
conn.close()

The AdventureWorks2008LT sample database has customer, product, address, and order tables (etc). Some of the string data in these tables is unicode.

The query works, for the first couple rows. I see the expected output. But then, the script fails with this message:

Traceback (most recent call last):
  File "C:\dev\python\query-1.py", line 24, in <module>
    print item
  File "C:\Python27\lib\site-packages\adodbapi\adodbapi.py", line 651, in __str__
    return str(tuple([str(self._getValue(i)) for i in range(len(self.rows.converters))]))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 19: ordinal not in range(128)

…which is very much not helpful. To me.

I gather that adodbapi is trying to encode a u’\xe9′ character into ASCII. I understand why that will fail.
I suppose it’s trying to do that as part of the print statement.

Why is it trying to encode the character into ASCII?
How can I tell it to just use UTF-8?

ps: I am running the script from the cmd.exe prompt in Windows. Does this mean stdout is always ASCII?

eg, \python27\python.exe -c "import sys; print(sys.stdout.encoding)"

gives me ‘cp437’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:46:57+00:00Added an answer on May 31, 2026 at 6:46 pm

    I was able to get the script to run to completion, printing all retrieved rows, by modifying the output portion to do this:

    # show the result
    result = cur.fetchall()
    for item in result:
        print repr(item)
    

    instead of this:

    # show the result
    result = cur.fetchall()
    for item in result:
        print item
    

    So the problem is in fact the use of str within adodbapi as Borealid said in a comment. But that is not necessarily a blocking problem. Normally when retrieving rows from a database query, people don’t simply want a string representation of a row; they want to retrieve the values in the individual columns. My conclusion is that this problem is sort of an artificial problem, due to the way I was building a test app.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a python novice and am struggling with some concepts here - any help
All right, I'm a novice at python, and here's the snippet of code in
My python level is Novice. I have never written a web scraper or crawler.
A question from a complete Python novice. I have a column array where I
I'm trying to build a Python application using pyGTK, treads, and sockets. I'm having
I'm a Python novice, trying to use pyCurl. The project I am working on
I am novice to python and I am trying to understand a basic error
I notice this thread: Fastish Python/Jython IPC , and I have a similar problem,
Python has this wonderful way of handling string substitutions using dictionaries: >>> 'The %(site)s
I'm trying to run mod_wsgi 3.1 under Apache 2.2.14 using a non-default python installation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.