Got it working! (Thanks @001 for getting me in the right direction!)
Final script:
import requests
import sys
import time
import json
url = 'https://www.virustotal.com/api/v3/files/{}'
headers = {"accept": "application/json",
"x-apikey": "<apikey>"}
inf = input("What hash file?")
with open(inf, "r") as f:
with open("hashout.txt", "w") as output:
for line in f:
HASH = str(line).strip()
url = 'https://www.virustotal.com/api/v3/files/{}'.format(HASH)
response = requests.get(url, headers=headers)
if response.status_code != 200:
print("Hash Not Found")
output.write("Not Found")
else:
data = response.json()
for key in data.items():
if key == "md5":
md5 = str(value)
print(md5)
output.write(md5)
time.sleep(16) # VirusTotal Public API allows only 4 requests per minute, Do not change the sleep duration.
print("File Complete")