How to scan file using API in VirusTotal in Python - python

I'm creating a script that supposed to run virus scan in TotalVirus, on a file/s that given by the user, using TotalVirus's API (https://developers.virustotal.com/reference) .
The goals of my script are:
File Name- The use will give a file name and the file path's, and the script will scan the file in VirusTotal.
A path- The script will scan all of the files from the path that given by the user.
A list- The user will give a path, and list of files in that path. the script will scan the files in the list in VirusToal.
I decided to use the script from here - https://github.com/blacktop/virustotal-api/blob/master/virus_total_apis/api.py
I copy and pasted the code in the link from the above, and when I tried to call the funciton "scan_file", with this code:
tmp = PublicApi.scan_file('MyAPICodeIsHere', '7z.exe', 'C:\\Program Files\\7-Zip\\7z.exe', '7z.exe', '2')
This is the error I received:
Traceback (most recent call last):
File "C:/Users/OSUser/.PyCharmCE2019.1/config/scratches/testtuhs.py", line 877, in <module>
tmp = PublicApi.scan_file('64be7cea7bcabaf2be366253b247a6a1075e2a90a71bbc45058398bb8638f8db', '7z.exe', 'C:\\Program Files\\7-Zip\\7z.exe', '7z.exe', '2')
File "C:/Users/OSUser/.PyCharmCE2019.1/config/scratches/testtuhs.py", line 65, in scan_file
params = {'64be7cea7bcabaf2be366253b247a6a1075e2a90a71bbc45058398bb8638f8db': self.api_key}
AttributeError: 'str' object has no attribute 'api_key'
My guess is that I called the fucntion - "scan_file" incorrectly.
How can I call the function "scan_file" correctly, so when I call it, it will scan the file in VirusTotal?
P.S - The code from the link allow many more functions with insturctions but I didn't understand how to use/call them.
Thank you.

Related

Unable to extract some files from zip file

I have made a python script which takes the latest files from university e-class (lectures in pdf formats, scripts etc) via requests and downloads them. After downloading it automatically extracts the zip on the specific folder i want. But the extraction function sometimes it gets stuck on the same files.
The function is this:
import zipfile
from tqdm import tqdm
zipnm = 'Διαδικτυακά και Φορητά Πληροφοριακά Συστήματα'
quartls = '6'
def extractZip(zipName, quartInd):
with zipfile.ZipFile('./'+zipName+'.zip', 'r') as zip_ref:
for member in tqdm(zip_ref.infolist(), desc='Extracting '):
try:
zip_ref.extract(member, './'+quartInd+'° εξάμηνο/'+zipName)
except zipfile.error as e:
print(e)
if __name__ == '__main__':
extractZip(zipnm, quartls)
When running on terminal it throws this:
PS Microsoft.PowerShell.Core\FileSystem::\\192.168.1.200\[REDACTED]> python .\test.py
Extracting : 39%|███████████████████████████ | 11/28 [00:00<00:01, 12.04it/s]
Traceback (most recent call last):
File "\\192.168.1.200\[REDACTED]\test.py", line 18, in <module>
extractZip(zipsd, quartsd)
File "\\192.168.1.200\[REDACTED]\test.py", line 12, in extractZip
zip_ref.extract(member, './'+quartInd+'° εξάμηνο/'+zipName)
File "C:\Users\[REDACTED]\AppData\Local\Programs\Python\Python39\lib\zipfile.py", line 1616, in extract
return self._extract_member(member, path, pwd)
File "C:\Users\[REDACTED]\AppData\Local\Programs\Python\Python39\lib\zipfile.py", line 1683, in _extract_member
os.mkdir(targetpath)
FileExistsError: [WinError 183] Δεν είναι δυνατή η δημιουργία ενός αρχείου όταν αυτό το αρχείο υπάρχει ήδη: '6° εξάμηνο\\Διαδικτυακά και Φορητά Πληροφοριακά Συστήματα\\Εργαστήρια\\Lab 5 - Introduction to PHP'
When I'm trying to extract the zip file manually, it sticks on 2 files that I either can retry or abort the files from extracting. Although the other files that already exist show me the options to replace them. My question is, why is this happening on these 2 files and not letting me to replace them like the others? Are the files corrupted (although I checked their size and looking if EOF is missing but nothing suspicious)?
P.S. I don't want on my script file to check if exists to exclude them I just want to find the source of the problem so I can act accordingly.
P.S.#2:
The files that get extracted are actually in an Ubuntu server machine which I access via Samba on Windows and then I run the script or doing anything with the files.

ConfigParser instance has no attribute '[extension]'

I am learning python and I am trying to do a simple task of reading information from a config file.
So using the Python Doc and this similar problem as a reference I created two files.
This is my config file config.ini (also tried config.cfg)
[DEFAULT]
OutDir = path_to_file/
[AUTH]
TestInt = 100
TestStr = blue
TestParse = blua
and this is my python file test.py
import ConfigParser
from ConfigParser import *
config = ConfigParser()
config.read(config.cfg)
for name in config.options('AUTH'):
print name
out = config.get('DEFAULT', 'OutDir')
print 'Output directory is ' + out
however when running the command python test.py I am erroring out and receiving this error
Traceback (most recent call last):
File "test.py", line 7, in <module>
config.read(config.cfg)
AttributeError: ConfigParser instance has no attribute 'cfg'
Note: I thought that meant it the extension couldn't be read so I created the .ini file and changed it in the code and I received the same error but it instead read ...has no attribute 'ini'
I am not sure what I am doing wrong since I am doing the exact same as the python doc and the solution someone used to fix this similar issue.
config.read takes a string as its argument. You forgot to quote the file name, and config was coincidentally the name of a Python object (the module) that potentially could have a cfg attribute. You'd get an entirely different error if you had written config.read(foobarbaz.ini).
The correct line is
config.read('config.cfg') # or 'config.ini', if that's the file name

Getting "global name 'FbxManager' is not defined"

I am working on creating a WebGL interface for which I am trying to convert FBX models to JSON file format in an automated process using python file, convert_fbx_three.py (from Mr. Doob's GitHub project) from command line.
When I try the following command to convert the FBX:
python convert_fbx_three.py Dolpine.fbx Dolpine
I get following errors:
Error in cmd:
Traceback (most recent call last):
File "convert_fbx_three.py", line 1625, in <module>
sdkManager, scene = InitializeSdkObjects()
File "D:\xampp\htdocs\upload\user\fbx\FbxCommon.py", line 7, in InitializeSdkObjects
lSdkManager = KFbxSdkManager.Create()
NameError: global name 'FbxManager' is not defined
I am using Autodesk FBX SDK 2012.2 available here on Windows 7.
Can you please try the following:
import FbxCommon
.
.
.
lSdkManager, lScene = FbxCommon.InitializeSdkObjects()
You probably need to add environment variables pointing to the folder that contains fbx.pyd, FbxCommon.py, and fbxsip.pyd prior to calling anything in those modules.

libtorrent-python problems, "no such file or directory" when there clearly is

First of all, here's the code
#!/usr/bin/env python3.4
import libtorrent as lt
import os
fs = lt.file_storage()
lt.add_files(fs, "/var/mirror/packages/") # There are two files in this directory
t = lt.create_torrent(fs, flags = 1&8&16) # 1 = Optimization, 8 = Symbolic links, 16 = calculate file hashes.
t.add_tracker("udp://tracker.[private].com:80")
print(os.path.isdir("/var/mirror/packages/"))
lt.set_piece_hashes(t,"/var/mirror/packages/")
print(t.generate())
And here's what happens when I run it
True
Traceback (most recent call last):
File "./test.py", line 9, in <module>
lt.set_piece_hashes(t,"/var/mirror/packages/")
RuntimeError: No such file or directory
This is the page I got this from
I have browsed around the bindings, but I can't find the set_piece_hashes sources. It returns the same error code when I change the path to "." or "/" (keeping the add_files path the same)
Anyone know what I'm doing wrong? I can't find any sort of documentation other than the site I linked above
Turns out set_piece_hashes wants the parent directory of the directory you created the filestore with. After I fixed that, I now get another error, which is a known bug in libtorrent here

Problems with GWTP mergelocales.py

I'm trying to use the mergelocales.py script but I can't get it working.
In my ui.xml (the one that I am using to test it) I have this locales:
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
ui:generateFormat='com.google.gwt.i18n.rebind.format.PropertiesFormat'
ui:generateKeys="com.google.gwt.i18n.rebind.keygen.MD5KeyGenerator"
ui:generateLocales="en_US, es_ES"
ui:defaultLocale="es_ES"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
Then I compile my project using "-extra extras" argument. This generates an "extras" directory in my project wich haves a folder called "myModule" and inside this folder are the generated .properties files:
/myproject/extras/myModule/com.mycompany.myproject.client.mvp.views.MyViewImplMyViewImplUiBinderImplGenMessages_en_US.properties
/myproject/extras/myModule/com.mycompany.myproject.client.mvp.views.MyViewImplMyViewImplUiBinderImplGenMessages_es_ES.properties
Now, I am trying to run the mergelocales.py to get the LocalizableResources*.properties files and when I try to run:
python2.5 ~/Downloads/mergelocales.py extras/myModule src/main/java/com/google/gwt/i18n/client/
I get the following stack trace:
Skipping non-default locale in extra directory: com.mycompany.myproject.client.mvp.views.MyViewImplMyViewImplUiBinderImplGenMessages_en_US.properties
Skipping non-default locale in extra directory: com.mycompany.myproject.client.mvp.views.MyViewImplMyViewImplUiBinderImplGenMessages_es_ES.properties
Traceback (most recent call last):
File "/Users/admin/Downloads/mergelocales.py", line 497, in <module>
main()
File "/Users/admin/Downloads/mergelocales.py", line 131, in main
mergeLocales( args[0], args[1] )
File "/Users/admin/Downloads/mergelocales.py", line 466, in mergeLocales
pathname = os.path.join( resourcesDir, defaultLocaleFilename )
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/posixpath.py", line 60, in join
if b.startswith('/'):
AttributeError: 'NoneType' object has no attribute 'startswith'
Is there something that I am missing to get this script working?
Now, I am trying to run the mergelocales.py to get the LocalizableResources*.properties files and [...] I get the following stack trace...
You have to create the blank LocalizableResource.properties files manually yourself and they will be populated by mergeLocales script. See here:
Let’s say we would like our application to also be available in French. We need to create two empty files named LocalizableResource.properties and LocalizableResource_fr.properties. The LocalizableResource.properties will contain the default (English) texts, whereas the LocalizableResource_fr.properties, will contain the French texts. Those files should be located in src/main/resources/com/google/gwt/i18n/client.
from http://blog.arcbees.com/2015/09/15/i18n-using-gwts-uibinder/

Categories