此文章将会记录我以后遇到的bug以及解决方式
2022.10.24
1.
数字里只有 if 0是 False 其他的都是True
if -1:
print('True')
这是会输出True的
函数想返回False的话要么返回False 要么是0要么是[] 或者是{}或者是’'或者是None之类的
return False
return []
return {
}
return ''
return ""
return None
return 0
等等
2.
数据库批量插入加入有唯一索引重复或者主键重复的情况勿直接使用INSERT INTO
,会导致整批都插入不进去,应该用INSERT IGNORE INTO
。
2022.10.25
1.Scrapy 出现AttributeError: module ‘OpenSSL.SSL’ has no attribute ‘TLS_METHOD’
解决方案
pip uninstall cryptography
pip install cryptography==36.0.2
pip uninstall pyOpenSSL
pip install pyOpenSSL==22.0.0
2022.10.26
1. scrapy-bloomfilter 误判问题
问题出在了
self.bf = BloomFilter(self.r, key='scrapy-bloomfilter', bit=10, hash_number=6)
为了节省空间吧bit调整到了10
也就是2的10次方
官方介绍如下
# 去重类,要使用 BloomFilter 请替换 DUPEFILTER_CLASS
DUPEFILTER_CLASS = "scrapy_redis_bloomfilter.dupefilter.RFPDupeFilter"
# 哈希函数的个数,默认为 6,可以自行修改
BLOOMFILTER_HASH_NUMBER = 6
# BloomFilter 的 bit 参数,默认 30,占用 128MB 空间,去重量级 1 亿
BLOOMFILTER_BIT = 30
默认是30,我调到了30 ,误判率增大了很多,导致把该跑的也去重了丢了很多数据。
30是128M 一亿指纹,32 是512 四亿指纹, 依次类推,要多少放多少。
2. scrapy TypeError: to_bytes must receive a str or bytes object, got int
Post请求的时候data键值对的值不能为整型,必须是字符串~
2022.10.27
1. 深浅拷贝问题
Lis = []
dic = {
'pageSize': 10,
'pageIndex': 1,
}
for page in range(1, 3):
dic['pageIndex'] = page
print(dic)
Lis.append(dic)
print(Lis)
输出的结果是
遍历输出的是1,2 。 放到列表就是2,2了
解决方式:
Lis.append(copy.deepcopy(dic))
2.Scrapy Post 发送Json问题
yield scrapy.Request(url=self.start_urls[0], method='POST', body=json.dumps(data), callback=self.parse,
dont_filter=True, headers={
'Content-Type': 'application/json'})
记得要加上 headers={'Content-Type': 'application/json'}
2022.11.02
1.gitignore 不生效问题
git rm -r --cached . // 清除分支的缓存
git add . // 重新添加
git commit -m 'update .gitignore' // 提交信息
2 .在终端黏贴出现多余字符串 00~ 01~
终端输入
printf '\e[?2004l'
2022.11.03
1. copilot 失效问题
我的做法是先添加git的host文件
nslookup github.global.ssl.fastly.Net
nslookup github.com
执行上面的两行代码得到ip地址
然后编写host文件
sudo vim /etc/hosts
粘贴下面的两行~
github.com 20.205.243.166
github.global.ssl.fastly.Net 199.193.116.105
然后刷新缓存
sudo service networking restart
sudo service network-manager restart
sudo systemctl is-active systemd-resolved
这个时候还是得不到copilot的回应,我的做法是,去git上随便copy一个git仓库,克隆下来。
就能得到copilot的回应了(不知道为啥,应该是建立了某种连接了)
然后删掉拉下来的代码库就行了。
2022.12.20
1. Vscode 键盘粘贴错位问题
解决方式
下载插件
Paste and Indent
按照主页要求配置keybindings.json文件即可。