私はPythonスクリプトで2つの関数を持っています。Python3はDBクエリの結果を個々の文字列に変換します
最初のデータはWHERE句でデータベースからデータを取得しますが、2番目の関数はこのデータを使用し、結果を繰り返してファイルをダウンロードします。
結果をタプルとして出力できますか?
[('mmpc',), ('vmware',), ('centos',), ('redhat',), ('postgresql',), ('drupal',)]
しかし、私はダウンロード機能は、ここでresponse
変数
のURLにそれを追加することができるように文字列として、各要素を反復処理するために必要な機能が含まれているダウンロード・スクリプトのコードです: -
import requests
import eventlet
import os
import sqlite3
# declare the global variable
active_vuln_type = None
# Get the active vulnerability sets
def GetActiveVulnSets() :
# make the variable global
global active_vuln_type
active_vuln_type = con = sqlite3.connect('data/vuln_sets.db')
cur = con.cursor()
cur.execute('''SELECT vulntype FROM vuln_sets WHERE active=1''')
active_vuln_type = cur.fetchall()
print(active_vuln_type)
return(active_vuln_type)
# return str(active_vuln_type)
def ExportList():
vulnlist = list(active_vuln_type)
activevulnlist = ""
for i in vulnlist:
activevulnlist = str(i)
basepath = os.path.dirname(__file__)
filepath = os.path.abspath(os.path.join(basepath, ".."))
response = requests.get('https://vulners.com/api/v3/archive/collection/?type=' + activevulnlist)
with open(filepath + '/vuln_files/' + activevulnlist + '.zip', 'wb') as f:
f.write(response.content)
f.close()
return activevulnlist + " - " + str(os.path.getsize(filepath + '/vuln_files/' + activevulnlist + '.zip'))
現在のところ、それは('mmpc',).zip
として壊れた.zipファイルを作成しますので、それが唯一の作成のいずれかとして最初の1のためにmmpc.zipされるだろうが、それは、リストを反復処理していないように見える実際のファイルではありませんDBからの最初の結果のzipファイル、他のものではなくprint(i)
が返されます。[('mmpc',), ('vmware',), ('centos',), ('redhat',), ('postgresql',), ('drupal',)]
スクリプトが動作していると思っているのでトレースバックはありません。
'active_vuln_type = cur.fetchall()'を 'active_vuln_type = [curlのxのためのx [0]'のように置き換えますか? – Abdou
私はそのレベル - 脳のおならの瞬間にそれをループするとは思わなかった!私はそれを渦巻くよ! – Luke
それは私に最初の結果を正しく取得しますが、反復しておらず、結果の残りの部分を取得していません – Luke