我正在尝试使用VirusTotal API进行异步POST功能。
当我使用请求时,一切正常。但是aiohttp无缘无故地给出了400错误请求。
请求
import requests
headers = {'x-apikey' : '3f211a1a2f3e0092832063970c780db4391d79ba15ee907f7c950d870e54a84f'}
def VirusTotal(path):
api_url = 'https://www.virustotal.com/api/v3/files/upload_url'
query = requests.get(api_url, headers=headers)
json = query.json()
url = json["data"]
files = {"file": (open(path, "rb").read())}
result = requests.post(url, headers=headers, files=files)
result.json() # <-- 200
VirusTotal(path)
aiohttp
import asyncio
import aiohttp
headers = {'x-apikey' : '3f211a1a2f3e0092832063970c780db4391d79ba15ee907f7c950d870e54a84f'}
async def VirusTotal(path):
session = aiohttp.ClientSession()
api_url = 'https://www.virustotal.com/api/v3/files/upload_url'
query = await session.get(api_url, headers=headers)
json = await query.json()
url = json["data"]
files = {"file": (open(path, "rb").read())}
result = await session.post(url, headers=headers, data=files)
await result.json() # <-- 400
loop = asyncio.get_event_loop()
loop.run_until_complete(VirusTotal(path))