带有https的Kivy UrlRequest [英] Kivy UrlRequest with https

查看:113
本文介绍了带有https的Kivy UrlRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取Python 3.7 Kivy代码以使用UrlRequest检索https Web数据.代码与http可以正常工作,但是将URL更改为任何https时我没有任何数据.当我同时使用http或https编译并运行时,两者都运行无误.我需要添加导入以使https工作吗?这是测试代码.谢谢.

I'm trying to get Python 3.7 Kivy code to retrieve https web data using UrlRequest. Code works fine with http, but I get no data when I change the url to any https. When I compile and run with both http or https, both run without errors. Is there an import I need to add to make https work? This is test code. Thanks.

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()

MainApp().run()

推荐答案

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)) 

我在UrlRequest之后也添加了verify = False,也添加到了原始代码中.该代码运行并生成html数据的打印语句.尽管这可以解决https问题,但我不知道此明显的SSL问题是否已得到正确解决.

I added verify=False after the UrlRequest, also to the original code. The code runs and generates a print statement of html data. Although this solves the https problem, I don't know if this apparent SSL issue has been addressed correctly.

这篇关于带有https的Kivy UrlRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆