Home>

There is a SQL query that is executed from a python script.

The problem is that a field that is not in the database produces non-utf8 characters. How can this be adequately recoded into Cyrillic? In the Python script itself or on the base side for this particular variable? When a query is executed in pure sql, all the norms in the database are displayed in Cyrillic.

In python, there is a connection to mssql via pymssql.

Here's the request:

SELECT
CASE WHEN c_object_mane= '1' or c_object_mane= '2'
THEN 'Saint Petersburg'
WHEN c_object_mane= '3'
THEN 'Moscow'
END AS c_object_adress, an. [C_object_mane], an. [C_house_name], an. [C_type_room], an. [C_room], an. [C_status_flat], an. [Lead_bujet], an. [C_an], an. [Ddu_date ]
FROM mssql_db as an where an.ddu_date >
= '2021-01-01'

When outputting, according to the logic, the cities of Moscow, St. Petersburg should normally be written, but only this comes out:

Name
Menus
Menus
Moscow
Menus
Menus
Menus
Menus
Menus
  • Answer # 1

    In general, changed the connection from pymssql to pyodbc and it worked.

  • Answer # 2

    In general, changed the connection from pymssql to pyodbc and it worked.