Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 来自PyQt GUI的HTTP POST请求?_Python_Pyqt4 - Fatal编程技术网

Python 来自PyQt GUI的HTTP POST请求?

Python 来自PyQt GUI的HTTP POST请求?,python,pyqt4,Python,Pyqt4,我想用PyQt设计器创建一个简单的gui,将一些URL发送到VirusTotal服务。这是一个可以每分钟发送4个URL的简单脚本,即: import simplejson import urllib import urllib2 url = "https://www.virustotal.com/vtapi/v2/url/scan" parameters = {"url": "http://www.virustotal.com", ... "apikey":

我想用PyQt设计器创建一个简单的gui,将一些URL发送到VirusTotal服务。这是一个可以每分钟发送4个URL的简单脚本,即:

import simplejson
import urllib
import urllib2
url = "https://www.virustotal.com/vtapi/v2/url/scan"
parameters = {"url": "http://www.virustotal.com",
...               "apikey":     "1fe0ef5feca2f84eb450bc3617f839e317b2a686af4d651a9bada77a522201b0"}
data = urllib.urlencode(parameters)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
json = response.read()
print json
{"response_code": 1,
 "verbose_msg": "Scan request successfully queued, come back later for the report",

 "scan_id": "1db0ad7dbcec0676710ea0eaacd35d5e471d3e11944d53bcbd31f0cbd11bce31-1320752364",

 "scan_date": "2014-01-08 11:39:24",

"url": "http://www.virustotal.com/",

"permalink": "http://www.virustotal.com/url/1db0ad7dbcec0676710ea0eaacd35d5e471d3e11944d53bcbd31f0cbd11bce31/analysis/1320752364/"}
我如何制作一个gui,用户可以将URL和api密钥放入gui中,并将请求发送给virustotal


我只需要一些指导,而不是一个完整的解决方案。

很简单:-

1) 使用QtDesigner将gui元素拖放到小部件上,然后保存它。例如virustotal.ui

2) 使用pyuic4将ui文件转换为python文件。(“pyuic4 virustotal.ui-o virustotal.py”)

3) 然后将上述给定代码复制到文件中

4) 通过按钮感知单击的信号,并为其分配一个插槽,用于打包参数字典,然后按常规操作

self.lineEdit1 = QtGui.QLineEdit(self)    #URL
self.lineEdit2 = QtGui.QLineEdit(self)    # API KEY
self.pushButton = QtGui.QPushButton(self)   # SEND BUTTON
QtCore.QObject.connect(self.pushButton , QtCore.SIGNAL("clicked()") , self.doIt)

def doIt(self):
    parameters = {"url": str(self.lineEdit1.text()),"apikey": str(self.lineEdit2.text())}
    data = urllib.urlencode(parameters)
    req = urllib2.Request(url, data)
    response = urllib2.urlopen(req)
    json = response.read()
    print json

这是代码如何运行的基本布局,必须根据您的需要进行进一步的详细说明。

好吧,您的回答非常有用,现在我知道如何使用PyQt,谢谢您,我的朋友。