Skip to content

Commit 89ab683

Browse files
committed
fix: avoid malshare client error occure when malware is triggered
1 parent eb2e118 commit 89ab683

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

your_daily_dose_malware/backends/malshare.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,24 @@
99

1010
load_dotenv()
1111

12+
API_KEY = os.getenv("MALSHARE_API_KEY")
1213

1314
def scrap_malshare():
1415
"""List hashes from the past 24 hours
1516
"""
1617
with Progress() as progress:
17-
api_key = os.getenv("MALSHARE_API_KEY")
18-
if api_key == "":
19-
rich.print("[red]Please set MALSHARE_API_KEY ")
18+
if API_KEY is None or API_KEY == "":
2019
return None
2120
try:
2221
response = requests.post(
2322
"https://malshare.com/api.php",
2423
verify=True,
25-
params={"api_key": api_key, "action": "getlist"},
24+
params={"api_key": API_KEY, "action": "getlist"},
2625
)
2726
response.raise_for_status()
2827
hashes = response.json()
2928
except requests.RequestException as err:
30-
rich.print(f"[red] An error occurred: {err}")
29+
rich.print(f"[red] Malshare will be skipped. An expected error occurred: {err} ")
3130
return None
3231
rich.print(f"[green] - Malshare: {len(hashes)} Samples")
3332
sha256_ids = [hashe["sha256"] for hashe in hashes]
@@ -43,7 +42,7 @@ def scrap_malshare():
4342
try:
4443
response = requests.post(
4544
"https://malshare.com/api.php",
46-
params={"api_key": api_key, "action": "getfile", "hash": sha256_id},
45+
params={"api_key": API_KEY, "action": "getfile", "hash": sha256_id},
4746
verify=True,
4847
)
4948
response.raise_for_status()

0 commit comments

Comments
 (0)