admin 发表于 2021-9-13 17:22:46

TypeError: 'encoding' is an invalid keyword argument for this function

TypeError: 'encoding' is an invalid keyword argument for this function今天测试自己的网站get一些参数:发现有问题报错:    with open('./bbs168x.html','w',encoding='utf-8') as fp:
TypeError: 'encoding' is an invalid keyword argument for this function
原始代码:with open('./bbs168x.html','w',encoding='utf-8') as fp:
    fp.write(page_text)
解决办法:
修改代码:import io   ###引入io模块
fp= io.open('./bbs168x.html',mode='w', encoding='utf-8')
再次执行:读取数据结束!!!Process finished with exit code 0
页: [1]
查看完整版本: TypeError: 'encoding' is an invalid keyword argument for this function