吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2878|回复: 3
收起左侧

[求助] python pymssql报错,大佬帮忙看看 到底错哪儿了。

[复制链接]
We. 发表于 2020-4-17 22:14
本帖最后由 We. 于 2020-4-17 22:19 编辑

小白自学python ,最近在倒腾sql数据库。根据教程一步一步来的,不知道错哪里了。
大佬帮忙看看。
[Python] 纯文本查看 复制代码
#coding=utf-8
import pymssql

class MSSQL:
    def __init__(self, host, user, pwd, db):
        self.host = host
        self.user = user
        self.pwd = pwd
        self.db = db

    def __GetConnect(self):
        if not self.db:
            raise (NameError, '没有设置数据库信息')
        self.conn = pymssql.connect(host=self.host, user=self.user, password=self.pwd, database=self.db, charset="utf-8")
        cur = self.conn.cursor()
        if not cur:
            raise (NameError, '链接数据库失败')
        else:
            return cur

    def ExeQuery(self,sql):
        cur = self.__GetConnect()
        cur.execute(sql)
        relist = cur.fetchall(sql)
        self.conn.close()
        return reslist

def main():
        ms = MSSQL(host="localhost", user="sa", pwd="", db="Inventory")
        reslist = ms.ExeQuery("select * from Inventory")
        for row in reslist:
            print(row)
if __name__ == '__main__':
    main()


然后报错的信息有点多给我看蒙了。

[Python] 纯文本查看 复制代码
C:\Users\admin\AppData\Local\Programs\Python\Python38\python.exe C:/Users/admin/PycharmProjects/untitled/car.py
C:/Users/admin/PycharmProjects/untitled/car.py:2: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
  import pymssql
Traceback (most recent call last):
  File "src\pymssql.pyx", line 636, in pymssql.connect
  File "src\_mssql.pyx", line 1957, in _mssql.connect
  File "src\_mssql.pyx", line 676, in _mssql.MSSQLConnection.__init__
  File "src\_mssql.pyx", line 1683, in _mssql.maybe_raise_MSSQLDatabaseException
_mssql.MSSQLDatabaseException: (20010, b'DB-Lib error message 20010, severity 8:\nUnable to allocate sufficient memory (localhost:1433)\nOperating System error during No error (12)\n')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/admin/PycharmProjects/untitled/car.py", line 34, in <module>
    main()
  File "C:/Users/admin/PycharmProjects/untitled/car.py", line 30, in main
    reslist = ms.ExeQuery("select * from Inventory")
  File "C:/Users/admin/PycharmProjects/untitled/car.py", line 22, in ExeQuery
    cur = self.__GetConnect()
  File "C:/Users/admin/PycharmProjects/untitled/car.py", line 14, in __GetConnect
    self.conn = pymssql.connect(host=self.host, user=self.user, password=self.pwd, database=self.db, charset="utf-8")
  File "src\pymssql.pyx", line 642, in pymssql.connect
pymssql.OperationalError: (20010, b'DB-Lib error message 20010, severity 8:\nUnable to allocate sufficient memory (localhost:1433)\nOperating System error during No error (12)\n')


进程已结束,退出代码 1

如果是单纯敲代码能实现需求,但是一到面对对象我就歇菜了,底子薄弱了些。

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

Lin5520 发表于 2020-4-17 23:20
我猜24,26,29行
Lin5520 发表于 2020-4-17 23:31
 楼主| We. 发表于 2020-4-18 08:24
Lin5520 发表于 2020-4-17 23:31
还有31,就是你定义是relist,结果返回reslist

十分感谢, 我傻了吧唧的。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-30 05:46

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表