Python get HTTP
-
I am trying to accessing web resources.
Main.qmlimport QtQuick 2.7 import Ubuntu.Components 1.3 //import QtQuick.Controls 2.2 import QtQuick.Layouts 1.3 import Qt.labs.settings 1.0 import io.thp.pyotherside 1.3 MainView { id: root objectName: 'mainView' applicationName: 'example-web.yourname' automaticOrientation: true width: units.gu(45) height: units.gu(75) Page { anchors.fill: parent header: PageHeader { id: header title: i18n.tr('Example Web') } Label { id: label1 anchors { top: header.bottom left: parent.left right: parent.right bottom: parent.bottom } text: 'Get Web' verticalAlignment: Label.AlignVCenter horizontalAlignment: Label.AlignHCenter } } Python { id: python Component.onCompleted: { addImportPath(Qt.resolvedUrl('../src/')); importModule('example', function() { python.call('example.speak',[], function(returnValue) { console.log(returnValue); label1.text=returnValue; }) }); } onError: { console.log('python error: ' + traceback); } } }import urllib.request import urllib3 def speak(): try: source = urllib.request.urlopen("http://webcode.me") except Exception as e: return str(e) else: html_bytes = source.read() html_str = html_bytes.decode("utf8") source.close() return html_str def speak2(): http = urllib3.PoolManager() try: source = http.request('GET', 'http://webcode.me') except Exception as e: return str(e) else: html_str = source.data.decode('utf-8') return html_strBoth examples work on a computer(clickable desktop), but when I run them on a phone, I get errors:
on urllib:<urlopen error [Errno -3] Temporary failure in name resolution>on urllib3:
HTTPConnectionPool(host='webcode.me', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0xa8111390>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))How can fix it? =( Help me please.
-
Find the * .apparmor file in the project folder.
Add permissions:{ "policy_groups": [ "content_exchange", "content_exchange_source", "networking", "webview" ], "policy_version": 16.04 }After that the program will work
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login