Spaces:
Runtime error
Runtime error
pengdaqian
commited on
Commit
•
d7ab57a
1
Parent(s):
8787dd3
fix now
Browse files
scan.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import pyclamd
|
|
|
2 |
|
3 |
from picklescan.scanner import (
|
4 |
scan_url,
|
@@ -43,12 +44,19 @@ def init_clamd():
|
|
43 |
return clamd
|
44 |
|
45 |
|
|
|
|
|
|
|
|
|
|
|
46 |
def clamd_file(file_path: str, clamd):
|
47 |
if file_path.startswith("http"):
|
48 |
-
import urllib.request
|
49 |
tmp_path = f'/tmp/clamd_{file_path.split("/")[-1].split("?")[0]}'
|
50 |
print("tmp_path ", tmp_path)
|
51 |
-
|
|
|
|
|
|
|
52 |
ret = clamd.scan_file(tmp_path)
|
53 |
if ret is None:
|
54 |
return {
|
|
|
1 |
import pyclamd
|
2 |
+
import urllib.response, requests
|
3 |
|
4 |
from picklescan.scanner import (
|
5 |
scan_url,
|
|
|
44 |
return clamd
|
45 |
|
46 |
|
47 |
+
headers = {
|
48 |
+
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
|
49 |
+
}
|
50 |
+
|
51 |
+
|
52 |
def clamd_file(file_path: str, clamd):
|
53 |
if file_path.startswith("http"):
|
|
|
54 |
tmp_path = f'/tmp/clamd_{file_path.split("/")[-1].split("?")[0]}'
|
55 |
print("tmp_path ", tmp_path)
|
56 |
+
resp = requests.get(file_path, headers=headers).content
|
57 |
+
with open(tmp_path, "wb") as f:
|
58 |
+
f.write(resp)
|
59 |
+
# urllib.request.urlretrieve(file_path, tmp_path)
|
60 |
ret = clamd.scan_file(tmp_path)
|
61 |
if ret is None:
|
62 |
return {
|