Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'Mysql' object has no attribute 'db' #4

Closed
Eigh18n opened this issue Mar 7, 2021 · 7 comments
Closed

AttributeError: 'Mysql' object has no attribute 'db' #4

Eigh18n opened this issue Mar 7, 2021 · 7 comments

Comments

@Eigh18n
Copy link

Eigh18n commented Mar 7, 2021

OS:Windows 10
Python version:Python 3.8.2
MySQL version:mysql-8.0.23-winx64
使用Mirai 2.4.0-MCL 1.0.5
config.json已配置与本机相符
数据全部导入到amiya库中,使用查询命令后有返回结果

select * from t_config_amiya where config_name = "amiya_name" AND config_keyword = "good_name"

在第四步报错

>python amiya.py
Building prefix dict from the default dictionary ...
Loading model from cache C:\Users\ADMINI~1\AppData\Local\Temp\jieba.cache
Loading model cost 1.344 seconds.
Prefix dict has been built successfully.
Traceback (most recent call last):
  File "amiya.py", line 8, in <module>
    from message.messageHandler import MessageHandler
  File "G:\QQbot\Mirai\amiya-bot\Amiya-Bot\message\messageHandler.py", line 21, in <module>
    function = FunctionsIndex()
  File "G:\QQbot\Mirai\amiya-bot\Amiya-Bot\functions\functionsIndex.py", line 31, in __init__
    module = importlib.import_module(module_path, package='functions')
  File "D:\Python18\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "G:\QQbot\Mirai\amiya-bot\Amiya-Bot\functions\userInfo\init.py", line 8, in <module>
    database = BaseController()
  File "G:\QQbot\Mirai\amiya-bot\Amiya-Bot\database\baseController.py", line 21, in __init__
    self.comb = Mysql(base_config)
  File "G:\QQbot\Mirai\amiya-bot\Amiya-Bot\database\sqlCombiner.py", line 7, in __init__
    self.db = pymysql.connect(
  File "D:\Python18\lib\site-packages\pymysql\__init__.py", line 94, in Connect
    return Connection(*args, **kwargs)
  File "D:\Python18\lib\site-packages\pymysql\connections.py", line 327, in __init__
    self.connect()
  File "D:\Python18\lib\site-packages\pymysql\connections.py", line 587, in connect
    self._get_server_information()
  File "D:\Python18\lib\site-packages\pymysql\connections.py", line 969, in _get_server_information
    packet = self._read_packet()
  File "D:\Python18\lib\site-packages\pymysql\connections.py", line 676, in _read_packet
    packet.raise_for_error()
  File "D:\Python18\lib\site-packages\pymysql\protocol.py", line 223, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "D:\Python18\lib\site-packages\pymysql\err.py", line 107, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1040, 'ny connections')
Exception ignored in: <function Mysql.__del__ at 0x0000015996FF9430>
Traceback (most recent call last):
  File "G:\QQbot\Mirai\amiya-bot\Amiya-Bot\database\sqlCombiner.py", line 19, in __del__
    self.close()
  File "G:\QQbot\Mirai\amiya-bot\Amiya-Bot\database\sqlCombiner.py", line 124, in close
    self.db.close()
AttributeError: 'Mysql' object has no attribute 'db'
@Eigh18n
Copy link
Author

Eigh18n commented Mar 7, 2021

使用快速启动quickStart.py也遇到了报错

>python quickStart.py Text
Building prefix dict from the default dictionary ...
Loading model from cache C:\Users\ADMINI~1\AppData\Local\Temp\jieba.cache
Loading model cost 1.305 seconds.
Prefix dict has been built successfully.
Testing started.
Enter a message and press enter to interact.
amiya
[2021-03-07 12:56:47][group][GID 1061935528][UID 736458622][administrator] amiya
Traceback (most recent call last):
  File "D:\Python18\lib\site-packages\urllib3\connection.py", line 159, in _new_conn
    conn = connection.create_connection(
  File "D:\Python18\lib\site-packages\urllib3\util\connection.py", line 84, in create_connection
    raise err
  File "D:\Python18\lib\site-packages\urllib3\util\connection.py", line 74, in create_connection
    sock.connect(sa)
OSError: [WinError 10049] 在其上下文中,该请求的地址无效。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Python18\lib\site-packages\urllib3\connectionpool.py", line 670, in urlopen
    httplib_response = self._make_request(
  File "D:\Python18\lib\site-packages\urllib3\connectionpool.py", line 392, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "D:\Python18\lib\http\client.py", line 1230, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "D:\Python18\lib\http\client.py", line 1276, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "D:\Python18\lib\http\client.py", line 1225, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "D:\Python18\lib\http\client.py", line 1004, in _send_output
    self.send(msg)
  File "D:\Python18\lib\http\client.py", line 944, in send
    self.connect()
  File "D:\Python18\lib\site-packages\urllib3\connection.py", line 187, in connect
    conn = self._new_conn()
  File "D:\Python18\lib\site-packages\urllib3\connection.py", line 171, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x0000016D6C5B0880>: Failed to establish a new connection: [WinError 10049] 在其上下文中,该请求的地址无效。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Python18\lib\site-packages\requests\adapters.py", line 439, in send
    resp = conn.urlopen(
  File "D:\Python18\lib\site-packages\urllib3\connectionpool.py", line 726, in urlopen
    retries = retries.increment(
  File "D:\Python18\lib\site-packages\urllib3\util\retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='0.0.0.0', port=8080): Max retries exceeded with url: /uploadImage (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000016D6C5B0880>: Failed to establish a new connection: [WinError 10049] 在其上下文中,该请求的地址无效。'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "quickStart.py", line 46, in <module>
    on_message(message_text, config['admin_id'], config['close_beta']['group_id'])
  File "quickStart.py", line 10, in on_message
    message.on_message({
  File "G:\QQbot\Mirai\amiya-bot\Amiya-Bot\message\messageHandler.py", line 116, in on_message
    result = action['func'](self_data)
  File "G:\QQbot\Mirai\amiya-bot\Amiya-Bot\message\replies\faceImage.py", line 27, in face_image
    return Reply(Image(path), at=False)
  File "G:\QQbot\Mirai\amiya-bot\Amiya-Bot\message\messageType.py", line 42, in __init__
    image_id = imageManager.image(path, 'group')
  File "G:\QQbot\Mirai\amiya-bot\Amiya-Bot\modules\resource\imageManager.py", line 26, in image
    return self.requests_image_id(resource, file_path, image_type)
  File "G:\QQbot\Mirai\amiya-bot\Amiya-Bot\modules\resource\imageManager.py", line 45, in requests_image_id
    response = self.request.post(self.url('uploadImage'), data=multipart_data, headers=headers)
  File "D:\Python18\lib\site-packages\requests\sessions.py", line 578, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "D:\Python18\lib\site-packages\requests\sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "D:\Python18\lib\site-packages\requests\sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "D:\Python18\lib\site-packages\requests\adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='0.0.0.0', port=8080): Max retries exceeded with url: /uploadImage (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000016D6C5B0880>: Failed to establish a new connection: [WinError 10049] 在其上下文中,该请求的地址无效。'))

@nsc8931
Copy link

nsc8931 commented Mar 7, 2021

是否可以提供一下你的config.json,请删除个人敏感信息

@Eigh18n
Copy link
Author

Eigh18n commented Mar 7, 2021

mirai-http-api的setting.yml

cors: 
  - '*'
host: 0.0.0.0
port: 8080
authKey: Wmy2005eithteen
cacheSize: 4096
enableWebsocket: false
report: 
  enable: false
  groupMessage: 
    report: true
  friendMessage: 
    report: true
  tempMessage: 
    report: true
  eventMessage: 
    report: true
  destinations: []
  extraHeaders: {}

heartbeat: 
  enable: false
  delay: 1000
  period: 15000
  destinations: []
  extraBody: {}

  extraHeaders: {}

amiya的config.json

{
    "self_id": 123,
    "self_passwords": "***",
    "admin_id": 736458622,
    "mirai_ok": false,
    "auth_key": "Wmy2005eithteen",
    "server": {
        "server_ip": "0.0.0.0",
        "server_port": 8080
    },
    "database": {
        "host": "localhost",
        "port": 3306,
        "user": "root",
        "password": "***",
        "db": "amiya"
    },
    "baidu_cloud": {
        "enable": false,
        "app_id": "",
        "api_key": "",
        "secret_key": ""
    },
    "message": {
        "limit": {
            "seconds": 10,
            "max_count": 3
        },
        "reply_text_max_length": 100
    },
    "close_beta": {
        "enable": false,
        "group_id": 1061935528
    }
}

@nsc8931
Copy link

nsc8931 commented Mar 7, 2021

请将amiya的config中"server_ip": "0.0.0.0"字段值更改为127.0.0.10.0.0.0仅能在服务器上使用,表示接受从任何ip地址发送的请求。为了安全起见建议将mirai的监听ip也更改为127.0.0.1127.0.0.1表示本机地址,这样应该可以解决quickstart的问题,请修改后检查python amiya.py是否仍会报错。

@Eigh18n
Copy link
Author

Eigh18n commented Mar 7, 2021

更改为127.0.0.1后可以连接了,admin账号收到了启动完毕的消息,但是在群聊尝试发送命令时并无反应,控制台有接收消息。
在发送启动完毕消息后,控制台有报错消息,如下

2021-03-07 13:20:29 V/Bot.923594412: Friend(736458622) <- 启动完毕
2021-03-07 13:20:29 E/net.mamoe.mirai-api-http: kotlinx.coroutines.JobCancellationException: StandaloneCoroutine was cancelled; job=StandaloneCoroutine{Cancelling}@1c5ff70
kotlinx.coroutines.JobCancellationException: StandaloneCoroutine was cancelled; job=StandaloneCoroutine{Cancelling}@1c5ff70

2021-03-07 13:20:29 W/stderr: SLF4J: Failed to load class "org.slf4j.impl.StaticMDCBinder".
2021-03-07 13:20:29 W/stderr: SLF4J: Defaulting to no-operation MDCAdapter implementation.
2021-03-07 13:20:29 W/stderr: SLF4J: See http://www.slf4j.org/codes.html#no_static_mdc_binder for further details.

@nsc8931
Copy link

nsc8931 commented Mar 7, 2021

请将miral的setting中enableWebsocket: false的值改为true,本项目实际上是一个websocket客户端

@Eigh18n
Copy link
Author

Eigh18n commented Mar 7, 2021

成功了。enableWebsocket我改过一次,然后启动后命令行狂刷Server not found. ,于是改了回去。
看来教程又要改一下子了

@Eigh18n Eigh18n closed this as completed Mar 7, 2021
vivien8261 pushed a commit that referenced this issue Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants