Python Aiohttp发出400个错误请求。但是请求很有效
我正在尝试使用VirusTotal API创建异步POST函数 当我使用请求时,一切正常。但aiohttp无缘无故给出了400个错误的请求 请求Python Aiohttp发出400个错误请求。但是请求很有效,python,python-requests,aiohttp,Python,Python Requests,Aiohttp,我正在尝试使用VirusTotal API创建异步POST函数 当我使用请求时,一切正常。但aiohttp无缘无故给出了400个错误的请求 请求 import requests headers = {'x-apikey' : '3f211a1a2f3e0092832063970c780db4391d79ba15ee907f7c950d870e54a84f'} def VirusTotal(path): api_url = 'https://www.virustotal.com/ap
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)
导入请求
标题={'x-apikey':'3f211a1a2f3e0092832063970c780db4391d79ba15ee907f7c950d870e54a84f'}
def病毒总数(路径):
美国石油学会https://www.virustotal.com/api/v3/files/upload_url'
query=requests.get(api\uURL,headers=headers)
json=query.json()
url=json[“数据”]
files={“file”:(打开(路径,“rb”).read())}
result=requests.post(url,headers=headers,files=files)
result.json()#我无法重新创建此错误。最后一行中唯一的错误似乎是:循环。运行\u直到\u完成(VirusTotal(path))
其中表示未定义路径。另外,您可以解释一下您尝试执行的操作吗?我无法重新创建此错误。最后一行中唯一的错误似乎是:循环。运行直到完成(VirusTotal(path))
其中表示未定义路径。另外,您可以解释一下您正在尝试执行的操作吗?
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))