已解决 求问如何使用Python的requests库mirai-api-http中上传图片
- 
					
					
					
					
 查阅文档之后看到需要以 multipart/form-data格式上传,然后查了一下怎么用requests上传这种格式,写出了如下代码with open("/tmp/c_exam.png", "rb") as f: res = requests.post( "http://localhost:9999/uploadImage", headers={ "sessionKey":session_key, "type":"friend", }, files = { "img": ("/tmp/c_exam.png", f.read()) # "img": ("/tmp/c_exam.png", b"") } )然而res.text内容为 {"code":400,"msg":"无效参数"}
 实在想不出如何解决,用Google搜索mirai-api-http+requests+图片也没找到合适的解法orz
- 
					
					
					
					
 file_path = "/tmp/c_exam.png" with open(file_path, "rb") as f: imageUrl = json.loads(requests.post( "http://localhost:9999/uploadImage", files = { "sessionKey":(None, session_key), "type":(None, "friend"), "img": (file_path, f.read()) } ).text)["url"]解决了解决了orz 
- 
					
					
					
					
 
- 
					
					
					
					
 如果写python可以试试nonebot2+mirai adapter的形式 
- 
					
					
					
					
 file_path = "/tmp/c_exam.png" with open(file_path, "rb") as f: imageUrl = json.loads(requests.post( "http://localhost:9999/uploadImage", files = { "sessionKey":(None, session_key), "type":(None, "friend"), "img": (file_path, f.read()) } ).text)["url"]解决了解决了orz 
- 
				Topic has been marked as solved M Michael1015198808
