Kivy UrlRequest with https

一世执手 提交于 2019-12-11 18:22:20

问题


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


回答1:


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

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://stackoverflow.com/questions/55816099/kivy-urlrequest-with-https

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!