0

我有一个 python 脚本,需要使用http.client有效负载包上传文件。我尝试使用request.post的参数上传文本文件,但系统崩溃并显示以下错误:

Exception has occurred: TypeError
request() got an unexpected keyword argument 'files'

如文档所述,我试图将文件参数作为元组传递。

代码:

import http.client
from IPython.core import payload



files = {'document': open("F:/AIenv/textAnalysis/testin2.txt","r",encoding = "utf-8")}

conn = http.client.HTTPSConnection("farasa-api.qcri.org") 

headers = { "content-type": "application/json", "cache-control": "no-cache", }

conn.request("POST", "/msa/webapi/lemma", files = files, headers=headers)
res = conn.getresponse()

data = res.read()

print(data.decode("utf-8"))
4

0 回答 0