Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
110 views
in Technique[技术] by (71.8m points)

python - Windows / Linux SQLAlchemy connector Conversion type Error

I've been working in a project that uses SQLAlchemy to work with a MySQL database. I've done all the tests in my Windows machine. The problem had come when I moved the project to the Ubuntu server 20.04. There I got the following error: Python 'float64' cannot be converted to a MySQL type. Doing some research I've found this similar case. The suggestion is just to use int() or float() to convert numbers explicitly. But a question still remains: Why should it work on windows and not on Linux?

Doing more research I've found that it is probably a problem of the connector, which it is not the same in Windows and Linux. Actually I had some previous problems because in Windows I instantiate the engine: db_config = 'mysql://{}:{}@localhost/{}?charset=utf8mb4'.format(db_user, db_pass, db_schema), this is, only specifying the dialect and not the connector. While in Linux, only work if I specify both: db_config = 'mysql+mysqlconnector://{}:{}@localhost/{}?charset=utf8mb4'.format(db_user, db_pass, db_schema)

On Windows I'm using the connector PyMySQL with Xampp 7.1.9 and DB 10.1.26-MariaDB with the engine InnoDB. On Linux I use the connector mysqlconnector with the server MySQL 8.0.22-0ubuntu0.20.04.3 and also the engine InnoDB. It is worth to mention that I only have troubles when a float64 is written on the DB.

So, after this long introduction (sorry for it) the specific questions are:

  1. Is it, actually, a problem of the connector? Or I'm missing something here?
  2. Is there a way to use the same code in Windows than in Linux? (maybe only adding the dialect and the connector on Linux)
  3. Should I program everything from now on, specifying the conversion float() every-time I write a float into the database?

Any clue to those questions is more than welcome.

question from:https://stackoverflow.com/questions/65898746/windows-linux-sqlalchemy-connector-conversion-type-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Thanks to @snakecharmerb I reallize that I only need to use the same connector. So everything get solved by using on Linux: mysql+pymysql://{}:{}@localhost/{}?charset=utf8mb4'.format(db_user, db_pass, db_schema). This is, using the connector PyMySQL instead of mysqlconnector.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...