0
votes

i have this error when i`m executing a chan.send command :

error1

this is my script:

chan.send("mysql --user='test' --password=mypw --database='bugs_mogis' --execute='select login_name, realname, last_seen_date from profiles where disabledtext = "";'")
    chan.send('\n')
    time.sleep(1)
    resp = chan.recv(9999)
    output = resp.decode('ascii').split(',')
    print (''.join(output))

    chan.close()

It`s strange cause in "putty" this command works but also i have this error error2

1

1 Answers

1
votes

You might have a problem with quotation marks in your SQL string.

"mysql --user='test' --password=mypw --database='bugs_mogis' --execute='select login_name, realname, last_seen_date from profiles where disabledtext = "";'"

In the last part you enclose ; in ", however your whole string starts and ends with ", so python understands it as ending one string and starting another, and then joining them together. This is how python sees your string: (check the difference at the end)

"mysql --user='test' --password=mypw --database='bugs_mogis' --execute='select login_name, realname, last_seen_date from profiles where disabledtext = ;'"

This way SQL doesn't like the where disabledtext = ; part. To make it work, instead of enclosing whole string in ", use """ (see multiline strings):

""" mysql --user='test' --password=mypw --database='bugs_mogis' --execute='select login_name, realname, last_seen_date from profiles where disabledtext = "";' """