小编bhu*_*dya的帖子

使用python 3.3.1连接到mysql数据库的密码错误

我是python的新手,试图通过编写连接到我们的mysql数据库并做一些事情的服务器脚本来学习一些知识。我有python 3.3.1和mysql 5.0.96(社区)。我安装了mysql连接器/ python,并尝试使用mysql开发人员站点上的示例代码进行基本连接。这是我简单的python脚本:

#!/usr/local/bin/python3


import sys
import mysql.connector

db_config = {
    'user': 'joebloggs',
    'password': 'cleartext_passwd',
    'host': '127.0.0.1',
    'database': 'mydb'
}
cnx = mysql.connector.connect(**db_config)
cursor = cnx.cursor()
query = ('select usable_name, user_id from user')
cursor.execute(query)
for (usable_name, user_id) in cursor:
    print("{} is the usable name of {d}".format(usable_name, user_id))
cursor.close()
cnx.close()
Run Code Online (Sandbox Code Playgroud)

但我在连接数据库时遇到错误

"Authentication with old (insecure) passwords "\
mysql.connector.errors.NotSupportedError: Authentication with old (insecure) passwords is not supported. For more information, lookup Password Hashing in the latest MySQL manual
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?任何帮助表示赞赏

python mysql python-3.x

5
推荐指数
1
解决办法
4024
查看次数

基于嵌套值使用 jq 过滤数组

我正在编写一些 bash 脚本来帮助自动化 AWS 资源的管理。我正在使用aws-cliand jq,到目前为止一切都很好。

我正在使用自定义标签标记我的资源。在某些情况下,我想根据KeyValue自定义标签过滤资源列表。但是我在制定一个简洁的jq查询来做到这一点时遇到了麻烦。

因此,例如,如果我的 ec2 实例的(修剪后的)JSON 输出类似于:

[
    {
        "PublicIpAddress": "11.22.33.44",
        "PrivateIpAddress": "55.66.77.88",
        "Tags": [
            {
                "Value": "live199.blah.com",
                "Key": "Name"
            },
            {
                "Value": "live-standalone",
                "Key": "hc-class"
            }
        ]
    }
]
[
    {
        "PublicIpAddress": "111.222.333.444",
        "PrivateIpAddress": "555.666.777.888",
        "Tags": [
            {
                "Value": "staging99.blah.com",
                "Key": "Name"
            },
            {
                "Value": "staging-standalone",
                "Key": "hc-class"
            }
        ]
    }
]
Run Code Online (Sandbox Code Playgroud)

...我需要在 whereTags.Key == "hc-class"和 中找到条目,Tags.Value = "staging-standalone"我该如何以简洁的方式做到这一点jq

非常感谢任何帮助。

json aws-cli jq

5
推荐指数
1
解决办法
3550
查看次数

标签 统计

aws-cli ×1

jq ×1

json ×1

mysql ×1

python ×1

python-3.x ×1