I'm writing an exporter in python that will get all the products from our database. Everything worked fine for me till I had to change my working environment from linux to windows.
So, our products have polish letters in them. Working on linux I didnt have to think about encoding when I was exporting data with pandas to csv. All the names, descriptions etc. had a proper spelling. But that changed when I tried my code on windows machine. After a little digging I found out that the problem shows up during sql query. Here is an example code:
import pymssql
server = "SERVER_IP"
user = "USER"
password = "PASSWORD"
database = "DATABASE"
try:
conn = pymssql.connect(server, user, password, database)
except pymssql.OperationalError as err:
print('Error!', err)
exit(1)
query = """
SELECT
tw_Id as Id
,tw_Rodzaj as Rodzaj
,tw_Nazwa as Nazwa
,tw_Opis as Opis
,tw_Symbol as sku
,tw_IdGrupa as Grupa
FROM dbo.tw__Towar
WHERE (tw_Zablokowany = 0 AND [tw_IdGrupa] in (2,5))
"""
cursor = conn.cursor()
cursor.execute(query)
row = cursor.fetchone()
print(row)
conn.close()
The result of this code on linux:
(3, 1, 'Skuter Cristal BIAŁY 60V', '3 kołowy skuter elektryczny biały 60V', 'CRI-WHI', 2)
And here we've got the same code on windows:
(3, 1, 'Skuter Cristal BIA£Y 60V', '3 ko³owy skuter elektryczny bia³y 60V', 'CRI-WHI', 2)
I find it kinda strange but I tried looking further. Checked my ms sql database, found out that with
select name, collation_name
from sys.databases
That the collation_name for my database is Polish_CI_AS so naturaly I tried
conn = pymssql.connect(server, user, password, database, charset="Polish_CI_AS")
but with no result.
And now I kinda dont know what to do. I want to know why this problem shows up on windows but not on linux and how I can fix this.