-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyqt5_get_request.py
executable file
·51 lines (34 loc) · 1.05 KB
/
pyqt5_get_request.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
QNetworkAccessManager in PyQt
In this example we get a web page.
Author: Jan Bodnar
Website: zetcode.com
Last edited: September 2017
'''
from PyQt5 import QtNetwork
from PyQt5.QtCore import QCoreApplication, QUrl
import sys
class Example:
def __init__(self):
self.doRequest()
def doRequest(self):
#url = "http://www.google.com"
url = "https://oradocs-corp.documents.us2.oraclecloud.com/documents/"
req = QtNetwork.QNetworkRequest(QUrl(url))
self.nam = QtNetwork.QNetworkAccessManager()
self.nam.finished.connect(self.handleResponse)
self.nam.get(req)
def handleResponse(self, reply):
er = reply.error()
if er == QtNetwork.QNetworkReply.NoError:
bytes_string = reply.readAll()
print(str(bytes_string, 'utf-8'))
else:
print("Error occured: ", er)
print(reply.errorString())
QCoreApplication.quit()
app = QCoreApplication([])
ex = Example()
sys.exit(app.exec_())