Yung_Cod3r2020-04-02 16:45:01
Yung_Cod3r, 2020-04-02 16:45:01

405 error when working with Virustotal API?

Hello! I want to understand what is wrong. I wanted to make an "antivirus" bot, it sends a file to Virustotal and gets the result from there! I work with their API - https://developers.virustotal.com/reference#api-re...

But, when I try to return the scan results, I get an error code 405.
My code:

import telebot
import requests
import json

vt_url = "https://www.virustotal.com/vtapi/v2/file/scan"
parameters = {"apikey": ""}
bot = telebot.TeleBot("")
keyboard = telebot.types.ReplyKeyboardMarkup(True, True)
keyboard.row("Проверить файл")

def start(message):
    bot.send_message(message.chat.id, "Привет! Этот бот поможет тебе проверить файл на вирусы!", reply_markup=keyboard)

@bot.message_handler(func=lambda message: message.text.lower() == "проверить файл", content_types = ['document', 'text'])
def send_file(message):
    bot_message = bot.send_message(message.chat.id, "Отправьте файл для проверки!")
    bot.register_next_step_handler(bot_message, check_file)

def check_file(message):

    file_info = bot.get_file(message.document.file_id)
    downloaded_file = bot.download_file(file_info.file_path)

    src = 'C:/Users/Test/Desktop/test/test/' + message.document.file_name
    with open(src, 'wb') as new_file:
    files = {'file': (f'{message.document.file_name}', open(f'{message.document.file_name}', 'rb'))}
    response = requests.post(vt_url, files=files, params=parameters)
    if response.status_code == 200:
        result = response.json()
        file_id = result.get('scan_id')
        params = {'apikey': '3c2593f315cf033afa5f40832d9770dfec033319c966b4c17f01cdb160c08584', 'resource': f'{file_id}'}
        response = requests.get(vt_url, params=params)
        if response.status_code == 200:


I would like to understand what excites her, and how to solve it. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Vlad Grigoriev, 2020-04-02

the error clearly tells you that you are using the wrong method
in the dock it is written: curl --request POST
and in the code: requests.get
for a get request you need to use a different handle there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question