gpt4 book ai didi

python - 属性错误 : __enter__ error when trying to query from MySQL

转载 作者:行者123 更新时间:2023-12-05 01:08:40 25 4
gpt4 key购买 nike

以下内容曾经对我有用。由于某种原因,它不再是了。

>>> import configparser
>>> from mysql.connector import connect, Error
>>> with open('file.cfg', 'r') as f:
... config_string = '[s]\n' + f.read()
...
>>> config = configparser.ConfigParser()
>>> config.read_string(config_string)
>>> with connect(host=config.get('s','HOST'),user=config.get('s','USER'),password=config.get('s','PASS'),database="db") as connection:
... with connection.cursor() as cursor:
... cursor.execute("select dt from tab limit 1")
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: __enter__
>>>

mysql_connector-2.2.9-cp37-cp37m-linux_x86_64.whl

Python 3.7.6(默认,2020 年 2 月 26 日,20:54:15)

最佳答案

解决方案:

pip uninstall mysql-connector-python
pip uninstall mysql-connector
pip install mysql-connector-python

我看到的问题是我在 mysql-connector-python 之后安装了 mysql-connector (已弃用)(新版本的 mysql 连接器)。你,让 mysql-connector-python 成为 python 可以使用的唯一库。

关于python - 属性错误 : __enter__ error when trying to query from MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65787230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com