【发布时间】:2019-05-01 22:53:00
【问题描述】:
我正在尝试获取 Python 3.7 Kivy 代码以使用 UrlRequest 检索 https 网络数据。代码适用于 http,但是当我将 url 更改为任何 https 时,我没有得到任何数据。当我使用 http 或 https 编译和运行时,两者都运行没有错误。我需要添加一个导入来使 https 工作吗?这是测试代码。谢谢。
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.network.urlrequest import UrlRequest
from functools import partial
class MainApp(App):
def build(self):
grid = GridLayout(cols=1)
button1 = Button(text="Press to say Hello",
on_release=self.run_Hello)
button2 = Button(text="Kivy UrlRequest",
on_release=self.run_UrlRequests)
blank_button = Button(text="Click me!")
grid.add_widget(button1)
grid.add_widget(button2)
grid.add_widget(blank_button)
return grid
def run_Hello(self, *args):
print("Hello")
def run_UrlRequests(self, *args):
for i in range(10):
self.r = UrlRequest("https://www.google.com", verify=False,
on_success=partial(self.update_label, i),
on_error=partial(self.error_label, i))
def update_label(self, i, *args):
print(i)
print("success")
print(self.r.result)
def error_label(self, i, *args):
print("failed")
print(i)
print(self.r.result)
MainApp().run()
【问题讨论】:
-
向我们展示你到目前为止所做的事情
标签: python-3.x https kivy urlrequest