def close_req_files(self):
#关闭 requests 打开的文件
for f in self.files.values():
f.close()
def test4_1_sensitiveword_upload(self):
# 上传文件
self.action_type = "sensitiveWord/upload"
self.files = {'file': open(path_testfile + 'sensitive_word-1.txt', 'rb')}
self.params = {
"functions": "sense_M",
"userToken": token,
}
self.r = sl.post(url + self.action_type, params=self.params, files=self.files)
print(self.r.text)
self.assertEqual(1, self.r.json()['code'])
self.assertIn("请求成功", self.r.text)
self.r.close()
self.close_req_files()
相关链接:https://stackoverflow.com/questions/20255124/too-many-open-files-using-requests-module