-2

I have started using VirusTotal & trying to generate URL report. The URL that I am using to test the code is "https://xyqhsservice-logg.in/" which has a 503 status code but somehow the API endpoint is not working. I checked the documentation and used the same endpoint get request I am new to VirusTotal API would be great if someone can help.
Below is my code:

import requests
# Your VirusTotal API key
api_key = "key"

# URL to query
url_to_query = "https://xyqhsservice-logg.in/"

# VirusTotal API endpoint for URL reports
url = f"https://www.virustotal.com/api/v3/urls/{url_to_query}"

# Set headers with your API key
 headers = {
 "x-apikey": api_key
  }

try:
   # Get URL report
   response = requests.get(url, headers=headers)
   if response.status_code == 503:
       url_info = response.json()
       print("URL Analysis Report:")
       print(f"URL: {url_info['data']['id']}")
       print(f"Scan Date: {url_info['data']['attributes']['last_analysis_date']}")
       print(f"Positives: {url_info['data']['attributes']['last_analysis_stats']['malicious']}")
   print(f"Total Scans: {url_info['data']['attributes']['last_analysis_stats']['total']}")
   print(f"Scan Results:")
   for engine, result in url_info['data']['attributes']['last_analysis_results'].items():
       print(f"  {engine}: {'malicious' if result['category'] == 'malicious' else 'clean'}")
   else:
      print(f"Error querying URL {url_to_query}: {response.text}")

   except Exception as e:
     print(f"Error querying URL {url_to_query}: {e}")

The error I am getting is:

Error querying URL https://xyqhsservice-logg.in/: {"error": 
{"code":"NotFoundError","message":"Resource not found."}}

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Nicolas
  • 51
  • 12
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Aug 26 '23 at 20:09

1 Answers1

0

Note that you're not getting a 503 because of the URL you're testing. You are getting a 503 from virustotal, because the request you sent was garbage.

You don't pass your test URL as part of the request URL. You put it in a JSON that gets sent as form data.

url_to_query = "https://xyqhsservice-logg.in/"

# VirusTotal API endpoint for URL reports
url = "https://www.virustotal.com/api/v3/urls/"

# Set up form data.
data = {
 "url": url_to_query
}

# Set headers with your API key
headers = {
 "x-apikey": api_key
}
...
   response = requests.post(url, headers=headers, json=data)
Tim Roberts
  • 48,973
  • 4
  • 21
  • 30