【问题标题】:Kivy 'UrlRequest' can't get jsonKivy 'UrlRequest' 无法获取 json
【发布时间】:2019-06-07 19:12:24
【问题描述】:

我正在尝试使用我的烧瓶 api 中的 kivy UrlRequest 模块获取 json 数据,但没有响应(不仅是 on_success...)。

当我在终端上使用curl 命令时效果很好(IP 是虚拟的)。

卷曲http://123.12.123.xxx:1234/name/foo.json

请问如何解决这个问题?

-client.py-

from kivy.network.urlrequest import UrlRequest

def success(req, result):
    print('success')

def fail(req, result):
    print('fail')

def error(req, result):
    print('error')

def progress(req, result, chunk):
    print('loading')

req = UrlRequest('http://123.12.123.xxx:1234/name/foo.json', on_success=success, on_failure=fail, on_error=error, on_progress=progress)
#>>
#<UrlRequest(Thread-1, started daemon 12792)>
#Press any key to continue . . .

# If using 'curl' command then success.
#{
#  "ResultSet": {
#    "Result": {
#      "Greeting": "Hello foo from flask!"
#    }
#  }
#}

【问题讨论】:

    标签: python kivy


    【解决方案1】:

    添加req.wait(),即等待请求完成(直到resp_status 不是None)。

    片段

    req = UrlRequest('http://123.12.123.xxx:1234/name/foo.json', on_success=success, on_failure=fail, on_error=error, on_progress=progress)
    req.wait()
    

    【讨论】:

    • 非常感谢您。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多