【问题标题】:Python Error ValueError: View function did not return a response [duplicate]Python错误ValueError:查看函数没有返回响应[重复]
【发布时间】:2015-09-26 20:22:47
【问题描述】:

我的应用程序在运行 url http://localhost:81/ip_update/00178r 时出现错误 ValueError: View function did not return a response。 我无法解决,如果有人能帮助我,我将不胜感激

def ip_update (client):
    ip = request.remote_addr
    if 'r' in client:
        customer = cliente.rstrip ('r')
        urllib2.urlopen ('http://localhost:85/administration/ip_update/' + client + '/' + ip)
        time.sleep (3)
    else:
        server = 'localhost'
        port = 3306
        login = root
        password = 'password'

        mdb.connect con = (host = server, port = port = user login, passwd = password, use_unicode = True)
        cur = con.cursor ()

        cur.execute ("SELECT FROM tar_cliente ebas.tarefa WHERE tar_status = 'processing' and tar_cliente = '" + client $

        if cur.rowcount == 0:
            Data2 data = ()
            server = data2 ['clients'] [customer] ['server']
            urllib2.urlopen ('http://' + server + '/administration/ip_update/' + client + '/' + ip)
            time.sleep (3)
            return 'request for ip received for updating client code' + client
        else:
            return 'denied updating, client operation underway'

【问题讨论】:

  • 您在哪一行得到错误?你能发布完整的回溯吗?
  • 您发送给urlopen()的值不能在URL中包含空格;我已经删除了它们,前提是 Stack Overflow 告诉您不能在文本中包含此类 URL。它们在代码块中很好。
  • 你能再清理一下代码吗?例如,您的 Data2 data = () 行不是有效的 Python。您发布的代码不可能运行。

标签: python flask


【解决方案1】:

if 测试为真时,您的函数返回None

if 'r' in client:
    customer = cliente.rstrip ('r')
    urllib2.urlopen ('http: // localhost: 85 / administration / ip_update /' + client + '/' + ip)
    time.sleep (3)

在这种情况下,您也需要返回响应。在这里使用 sleep 是没有意义的。您所做的只是延迟向浏览器返回某些内容。

【讨论】:

  • @JeanEduardo:这就是我要说的;您没有在那里返回有效的响应。例如,返回 make_response() 结果或字符串。
  • 感谢您的帮助,问题不是开发此应用程序,也不懂python编程,您能告诉我这样做的正确方法吗?
  • 如果您不懂 Python 编程,从教程开始。我们将整天在这里弄清楚你做了多少,否则不知道。如果您至少不了解基础知识,我无法帮助您。
猜你喜欢
  • 2018-01-14
  • 1970-01-01
  • 1970-01-01
  • 2018-05-16
  • 1970-01-01
  • 2014-04-01
  • 2015-01-07
  • 1970-01-01
  • 2015-11-09
相关资源
最近更新 更多