python - 使用kivy请求url

标签 python django request kivy

我想从 django 编写的应用程序中获取一些数据,使用 kivy,django 服务器位于 127.0.0.1:8000。我看不到任何消息,结果是 None,我的请求脚本是

from kivy.network.urlrequest import UrlRequest
import urllib

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

params = urllib.urlencode({'@number': 12524, '@type': 'issue',
    '@action': 'show'})
headers = {'Content-type': 'application/x-www-form-urlencoded',
          'Accept': 'text/plain'}

UrlRequest('http://127.0.0.1:8000', on_success=success, on_failure=fail, on_error=fail, req_body=params, req_headers=headers)

最佳答案

如果您不在事件循环中运行代码,则它将不起作用。

要在没有 GUI 事件循环的情况下运行它,请使用 UrlRequest.wait方法:

...
req = UrlRequest('http://daum.net', on_success=success, on_failure=fail,
                 on_error=fail, req_body=params, req_headers=headers)
req.wait()

关于python - 使用kivy请求url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23872635/

相关文章:

javascript - 如何在接收数据时渲染(在一个路由挂载中渲染不止一次)

python - Django 测试 - 导入错误 : Start directory is not importable

Python poplib error_proto : line too long

django - django 中应用程序的媒体路径

javascript - 如何在不返回 Angular 数据的 http.post 请求上使用 'toPromise()'?

node.js - nodejs - 证书已过期

python - Numpy:将数组列表与另一个数组组合(np.choose 替代方案)

python - 如何在py2exe中包含py2exe找不到的psutil组件?

python - 每列的 django 计数

python - 一张表格共享数据分成多行