Ich habe eine Anwendung entwickelt, die pyQt in Python verwendet und einen Webbrowser und eine Tabelle verwendet, um die Header anzuzeigen, die mit der Browseranforderung kommen. hier ist mein Code: -Q Netzwerkzugriffsmanager in pyQt Python (Segmentierungsfehler Core Dumped)
import sys
from PyQt4.QtGui import QApplication, QTableWidget, QTableWidgetItem
from PyQt4.QtCore import QUrl
from PyQt4.QtWebKit import QWebView, QWebPage
from PyQt4.QtGui import QGridLayout, QLineEdit, QWidget, QHeaderView
from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest
class RequestsTable(QTableWidget):
header = ["url", "status", "content-type","cookies","user_agent"]
def __init__(self):
super(RequestsTable, self).__init__()
self.setColumnCount(5)
self.setHorizontalHeaderLabels(self.header)
header = self.horizontalHeader()
header.setStretchLastSection(True)
def update(self, data):
last_row = self.rowCount()
next_row = last_row + 1
self.setRowCount(next_row)
for col, dat in enumerate(data, 0):
if not dat:
continue
self.setItem(last_row, col, QTableWidgetItem(dat))
class Manager(QNetworkAccessManager):
def __init__(self, table):
QNetworkAccessManager.__init__(self)
self.finished.connect(self._finished)
self.table = table
def _finished(self, reply):
user_agent = str(reply.request().rawHeader("User-Agent"))
headers = reply.rawHeaderPairs()
headers = {str(k):str(v) for k,v in headers}
content_type = headers.get("Content-Type")
url = reply.url().toString()
status = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
status, ok = status.toInt()
cookies = headers.get("Set-Cookie")
self.table.update([url, str(status), content_type,cookies,user_agent])
if __name__ == "__main__":
app = QApplication(sys.argv)
grid = QGridLayout()
browser = QWebView()
browser.load(QUrl("http://www.indiatimes.com/"))
def on_html_available():
page = QWebPage()
page.setNetworkAccessManager(manager)
# problem is here
browser.setPage(page)
# if i dont use above line then it don't show any error but the headers don't get append in the table but if i use the above line it shows me the error segmentation fault
browser.loadFinished.connect(on_html_available)
requests_table = RequestsTable()
manager = Manager(requests_table)
grid.addWidget(browser, 3, 0)
grid.addWidget(requests_table, 4, 0)
main_frame = QWidget()
main_frame.setLayout(grid)
main_frame.show()
sys.exit(app.exec_())
aber der obige Code zeigt mir den Fehler
"core dumped segmentation fault"?
, was das Problem sein könnte? Bitte helfen Sie mir bei der Lösung dieses Problems.
danke, es hat geholfen –