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

  • SEARCH
  • Home
  • 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 1086423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:48:41+00:00 2026-05-16T22:48:41+00:00

I am connecting to a MS SQL server through SQL Alchemy, using pyodbc module.

  • 0

I am connecting to a MS SQL server through SQL Alchemy, using pyodbc module. Everything appears to be working fine, until I began having problems with the encodings. Some of the non-ascii characters are being replaced with ‘?’

The DB has a collation ‘Latin1_General_CI_AS’ (I’ve checked also the specific fields and they keep the same collation). I started selecting the encoding ‘latin1’ in the call of create_engine and that appears to work for Western European character (like French or Spanish, characters like é) but not for Easter European characters. Specifically, I have a problem with the character ć

I have been trying to select other encodings as stated on Python documentation, specifically the Microsoft ones, like cp1250 and cp1252, but I keep facing the same problem.

Does anyone knows how to solve those differences? Does the collation ‘Latin1_General_CI_AS’ has an equivalence on Python encodings?

The code for my current connection is the following

for sqlalchemy import *

def connect():
    return pyodbc.connect('DSN=database;UID=uid;PWD=password')

engine = create_engine('mssql://', creator=connect, encoding='latin1')
connection = engine.connect()

Clarifications and comments:

  • This problems happens when retrieving information from the DB. I don’t need to store anything.
  • At the beginning I didn’t specify the encoding, and the result was that, whenever a non ascii character was encountered on the DB, pyodbc raises a UnicodeDecodeError. I corrected that using ‘latin1’ as encoding, but that doesn’t solve the problem for all the characters.
  • I admit that the server is not on latin1, the comment is incorrect. I have been checking both the database collation and the specific fields collations and appears to be all in ‘Latin1_General_CI_AS’, then, how can ć be stored? Maybe I’m not correctly understanding collations.
  • I corrected a little the question, specifically, I have tried more encodings than latin1, also cp1250 and cp1252 (which apparently is the one used on ‘Latin1_General_CI_AS’, according to msdn)

UPDATE:

OK, Following these steps, I get that the encoding used by the DB appears to be cp1252: http://bytes.com/topic/sql-server/answers/142972-characters-encoding
Anyway, that appears to be a bad assumption as reflected on answers.

UPDATE2:
Anyway, after configuring properly the odbc driver, I don’t need to specify the encoding on the Python code.

  • 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-16T22:48:42+00:00Added an answer on May 16, 2026 at 10:48 pm

    You should stop using code pages and switch to Unicode. This is the only way of getting rid of this kind of problems.

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

Sidebar

Related Questions

I'm having a C++ application connecting to the MS SQL Server 2005 using CDynamicAccessor.
I'm connecting to SQL Server (2005) through Java using the Microsoft SQL Server JDBC
Having trouble connecting to SQL Server 2012 through my router firewall. I opened ports
I'm having issues connecting to a sql server database from an openbsd box using
The excel spreadsheet is connecting to SQL server 2005 using the connection string below:
I am having difficulty connecting my java code to sql server database. I can
I'm having a bit of trouble connecting to my SQL database through my C#
I'm using SQL server 2008r2 on a windows 2003 server and connecting to it
I am using ADO.Net for connecting to some Sql Server and Oracle databases, and
When connecting to sql server, I have the hardcoded string (local). Is this a

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.