discuz! database error Python开发 常见异常和解决办法
discuz! database error Python开发 常见异常和解决办法
1.创建外键关系报错 of that name on
是编程语言下的一款开源软件,提供了SQL工具包及对象关系映射(ORM)工具,使得在中操作MySQL更加简单。在给两个表创建外键关系时可能会报错:
sqlalchemy.exc.ArgumentError: Error creating backref 'xxx' on relationship 'xxx.xxx': property of that name exists on mapper 'mapped class xxx->xxx'
两个数据模型如下:
class Website(Base):
__tablename__ = 'website'
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(10), nullable=False)
link = Column(String(40), nullable=False)
orders = relationship('Order', backref='website')
class Order(Base):
__tablename__ = 'order'
id = Column(String(50), primary_key=True)
desc = Column(Text, nullable=False)
link = Column(String(80), nullable=False)
contact = Column(String(30))
category = Column(String(15))
is_valid = Column(Boolean, nullable=False)
add_time = Column(DateTime, default=datetime.now)
website = Column(Integer, ForeignKey('website.id'), nullable=False)
is_deleted = Column(Boolean, default=False)
其中一个order对于各,一个可以对应多个orderdiscuz! database error,在模型中定义关系时,为,这与Order中本来的字段重复而冲突discuz! database error Python开发 常见异常和解决办法,可以将该字段改名如wid,也可以将换名即可。
2.保存数据报错.utils..r

在使用保存数据时报错如下:
raise IllegalCharacterError
openpyxl.utils.exceptions.IllegalCharacterError
这是因为要保存的数据中存在一些认为是非法字符的字符串,需要进行替换discuz! database error Python开发 常见异常和解决办法,直接使用其提供的E进行转换即可,如下:
from openpyxl import Workbook
from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE
content = ILLEGAL_CHARACTERS_RE.sub(r'', content)
ws.cell(ridx, cidx).value = content
此时即可正常保存数据。
3.使用保存字符串到MySQL中时报错 value: ‘xF0…’ for ‘desc’ at row 1
在使用保存字符串数据到MySQL中会报错:
raise errors.get_exception(packet)
mysql.connector.errors.DatabaseError: 1366 (HY000): Incorrect string value: 'xF0x9Fx91x89xCFx84...' for column 'desc' at row 1
这是因为特殊字符xF0x9Fx91x89xCFx84…导致的,实际上这是表情字符,即Emoji对应的字符,但是因为MySQL一般的字符集是utf8,因此Emoji表情或者某些特殊字符是4个字节,而Mysql的utf8编码最多3个字节,所以数据插不进去。
解决方法有两种:
这两种方法中,个人建议使用第二种方法,只是对字符串进行处理,无需修改数据库的相关配置。
4.使用将字符串保存到MySQL报错: ‘’ has no ‘’
在使用库爬取到网页并使用lxml.etree包进行解析网页后,通过xpath获取到指定的元素和文本discuz! database error,并通过将文本保存到数据库中时报错:
raise errors.ProgrammingError(
sqlalchemy.exc.ProgrammingError: (raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely)
(mysql.connector.errors.ProgrammingError) Failed processing pyformat-parameters; Python '_elementunicoderesult' cannot be converted to a MySQL type
这是因为通过lxml.etree获取到的字符串可能是t,这是中字符串的一种,并未蹄冻将该类型变量转化为SQL对象的方法,因此需要强制转换为str类型,再进行数据保存,如下:
link = str(order.xpath('./div[1]/div[2]/a/@href')[0])
#...

order = OrderModel(id=yid, desc=desc, link=link, contact=contact, category='', pub_time=None, is_valid=is_valid, is_delete=False if is_valid else True)
order.website = website
session.add(order)
session.commit()
5. 11安装库报错 C++ 14.0 or is ,安装包丢失或损坏
的强大功能依赖于大量的第三方库,一般可以通过pip命令进行安装。但是一些库在安装时可能会报错 C++ 14.0 or is .,例如等库,以安装mxnet-cu101为例,报错如下:
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
----------------------------------------
ERROR: Failed building wheel for numpy
Running setup.py clean for numpy
ERROR: Command errored out with exit status 1:
command: 'E:Miniconda3envsnlpbasepython.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'XXX\Temp\pip-install-e8urqjmj\numpy_60732a99f04c4bc280c8ad695fdba369\setup.py'"'"'; __file__='"'"'XXX\Temp\pip-install-e8urqjmj\numpy_60732a99f04c4bc280c8ad695fdba369\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' clean --all
cwd: C:UsersLENOVOAppDataLocalTemppip-install-e8urqjmjnumpy_60732a99f04c4bc280c8ad695fdba369
Complete output (10 lines):
Running from numpy source directory.
一般可以通过下载第三方库的whl文件来安装,但是这样每次安装需要C++的库时,都需要手动下载whl文件,很麻烦。
另外一种解决方案是安装C++环境,常见的做法是安装 ,但是问题是软件太大,选择C++桌面开发环境之后,大概要安装10多G的文件,会占用很大的C盘空间。
另一种做法是下载 cpp build tools full.exe,安装 C++ 14.0。但是在 11中安装时,会出现以下问题:

即安装包丢失或损坏。
此时需要安装自带安装包的 cpp build tools full.exe,即可自动安装,如下:

安装完成,如下:

如需单独的 cpp build tools full.exe和自带安装包的 cpp build tools full.exe,可点击下载discuz! database error,并按照使用说明进行安装。
1. 本站所有资源来源于用户上传和网络,如有侵权请联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系站长处理!
6. 本站不售卖代码,资源标价只是站长收集整理的辛苦费!如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。
7. 站长QQ号码 2205675299
资源库 - 资源分享下载网 » discuz! database error Python开发 常见异常和解决办法
常见问题FAQ
- 关于资源售价和售后服务的说明?
- 代码有没有售后服务和技术支持?
- 有没有搭建服务?
- 链接地址失效了怎么办?
- 关于解压密码

