Home > other >  The same code, the results will be different in different running version is what reason is caused?
The same code, the results will be different in different running version is what reason is caused?

Time:11-27

As title, small white one, write a set of pytho code, basically realize is through sshtunnel, pymysql remote connect to the database query and retrieve data,
If no problem, when running environment for python2.7 but with python3.8 will not return the query results (also not an error, long time no output, stop running until the force), connect to the database code to the following, have a great god help have a look at is why?

The import pymysql as MySQLdb
The from sshtunnel import SSHTunnelForwarder

Def runSQLDB1 (SQL) :
With SSHTunnelForwarder (
(' 11.11.11.11, 2222),
Ssh_username="$user,"
Ssh_password="$pass",
# ssh_pkey="/home/kk/key pem",
Remote_bind_address='$address, (1111)
) as server1:
DB1=MySQLdb. Connect (host='127.0.0.1',
Port=server1 local_bind_port,
User='$user,
Password='$pass',
The db='$db,
Charset='utf8,
Cursorclass=MySQLdb. Your cursors. DictCursor)

Try:
CUSOR=DB1. Cursor ()
CUSOR. Execute (SQL)
Result=CUSOR. Fetchall ()
Except BaseException as e:
Print (e)
Finally:
CUSOR. Close ()
Return the result

CodePudding user response:

A great god, and I am a pure white, but I know, Python2, Python3 is incompatible, in different environments, so the results may be also different,

CodePudding user response:

Python2, Python3 incompatible!

CodePudding user response:

I know should be version compatibility problems, but I want to know if you want to run in 3.8 below, how should handle?

CodePudding user response:

reference 1/f, pine and 100 response:
great god, and I am a pure white, but I know, Python2, Python3 are incompatible, so the environment is different, the result may be also different,

I also is pure white, the code is a patchwork of copy to, so a problem is the blind ~ ~ ~
  • Related