- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
这是我使用 Restful 的 Flask 代码。
def get(self):
data = [{"id": "2", "lags": [{"id": "GBPQ1"}, {"id": "GBPQ2"},{"id": "GBPQ3"}, {"id": "BPQ4"}], "name": "GBP"}]
return jsonify(data)
这是我的错误:为什么?每个 jsoinlint 的有效 json。怎么解决?
curl http://0.0.0.0:5000/test/model/exposure/currencies/
curl http://0.0.0.0:5000/test/model/exposure/currencies/111111
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>ValueError: dictionary update sequence element #0 has length 3; 2 is required // Werkzeug Debugger</title>
<link rel="stylesheet" href="?__debugger__=yes&cmd=resource&f=style.css" type="text/css">
<!-- We need to make sure this has a favicon so that the debugger does not by
accident trigger a request to /favicon.ico which might change the application
state. -->
<link rel="shortcut icon" href="?__debugger__=yes&cmd=resource&f=console.png">
<script type="text/javascript" src="?__debugger__=yes&cmd=resource&f=jquery.js"></script>
<script type="text/javascript" src="?__debugger__=yes&cmd=resource&f=debugger.js"></script>
<script type="text/javascript">
var TRACEBACK = 140493007176848,
CONSOLE_MODE = false,
EVALEX = true,
SECRET = "hIZ55a7qO5d1PpF7ILd6";
</script>
</head>
<body>
<div class="debugger">
<h1>ValueError</h1>
<div class="detail">
<p class="errormsg">ValueError: dictionary update sequence element #0 has length 3; 2 is required</p>
</div>
<h2 class="traceback">Traceback <em>(most recent call last)</em></h2>
<div class="traceback">
<ul><li><div class="frame" id="frame-140493007176784">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/flask/app.py"</cite>,
line <em class="line">1836</em>,
in <code class="function">__call__</code></h4>
<pre>return self.wsgi_app(environ, start_response)</pre>
</div>
<li><div class="frame" id="frame-140493007177104">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/flask/app.py"</cite>,
line <em class="line">1820</em>,
in <code class="function">wsgi_app</code></h4>
<pre>response = self.make_response(self.handle_exception(e))</pre>
</div>
<li><div class="frame" id="frame-140493007177168">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py"</cite>,
line <em class="line">271</em>,
in <code class="function">error_router</code></h4>
<pre>return original_handler(e)</pre>
</div>
<li><div class="frame" id="frame-140493007176912">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py"</cite>,
line <em class="line">271</em>,
in <code class="function">error_router</code></h4>
<pre>return original_handler(e)</pre>
</div>
<li><div class="frame" id="frame-140493007176976">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/flask_cors/extension.py"</cite>,
line <em class="line">188</em>,
in <code class="function">wrapped_function</code></h4>
<pre>return cors_after_request(app.make_response(f(*args, **kwargs)))</pre>
</div>
<li><div class="frame" id="frame-140493007177296">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/flask/app.py"</cite>,
line <em class="line">1403</em>,
in <code class="function">handle_exception</code></h4>
<pre>reraise(exc_type, exc_value, tb)</pre>
</div>
<li><div class="frame" id="frame-140493007177424">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py"</cite>,
line <em class="line">268</em>,
in <code class="function">error_router</code></h4>
<pre>return self.handle_error(e)</pre>
</div>
<li><div class="frame" id="frame-140493007177360">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/flask/app.py"</cite>,
line <em class="line">1817</em>,
in <code class="function">wsgi_app</code></h4>
<pre>response = self.full_dispatch_request()</pre>
</div>
<li><div class="frame" id="frame-140493007177552">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/flask/app.py"</cite>,
line <em class="line">1477</em>,
in <code class="function">full_dispatch_request</code></h4>
<pre>rv = self.handle_user_exception(e)</pre>
</div>
<li><div class="frame" id="frame-140493007177616">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py"</cite>,
line <em class="line">271</em>,
in <code class="function">error_router</code></h4>
<pre>return original_handler(e)</pre>
</div>
<li><div class="frame" id="frame-140493007177232">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py"</cite>,
line <em class="line">271</em>,
in <code class="function">error_router</code></h4>
<pre>return original_handler(e)</pre>
</div>
<li><div class="frame" id="frame-140493007177488">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/flask_cors/extension.py"</cite>,
line <em class="line">188</em>,
in <code class="function">wrapped_function</code></h4>
<pre>return cors_after_request(app.make_response(f(*args, **kwargs)))</pre>
</div>
<li><div class="frame" id="frame-140493007177744">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/flask/app.py"</cite>,
line <em class="line">1381</em>,
in <code class="function">handle_user_exception</code></h4>
<pre>reraise(exc_type, exc_value, tb)</pre>
</div>
<li><div class="frame" id="frame-140493007177872">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py"</cite>,
line <em class="line">268</em>,
in <code class="function">error_router</code></h4>
<pre>return self.handle_error(e)</pre>
</div>
<li><div class="frame" id="frame-140493007177808">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/flask/app.py"</cite>,
line <em class="line">1475</em>,
in <code class="function">full_dispatch_request</code></h4>
<pre>rv = self.dispatch_request()</pre>
</div>
<li><div class="frame" id="frame-140493007178000">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/flask/app.py"</cite>,
line <em class="line">1461</em>,
in <code class="function">dispatch_request</code></h4>
<pre>return self.view_functions[rule.endpoint](**req.view_args)</pre>
</div>
<li><div class="frame" id="frame-140493007178064">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py"</cite>,
line <em class="line">477</em>,
in <code class="function">wrapper</code></h4>
<pre>resp = resource(*args, **kwargs)</pre>
</div>
<li><div class="frame" id="frame-140493007177680">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/flask/views.py"</cite>,
line <em class="line">84</em>,
in <code class="function">view</code></h4>
<pre>return self.dispatch_request(*args, **kwargs)</pre>
</div>
<li><div class="frame" id="frame-140493007177936">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py"</cite>,
line <em class="line">587</em>,
in <code class="function">dispatch_request</code></h4>
<pre>resp = meth(*args, **kwargs)</pre>
</div>
<li><div class="frame" id="frame-140493007178128">
<h4>File <cite class="filename">"/home/ubuntu/workspace/qtaapi/qtaapi/resources/model_exposure_currencies.py"</cite>,
line <em class="line">198</em>,
in <code class="function">get</code></h4>
<pre>return jsonify(data)</pre>
</div>
<li><div class="frame" id="frame-140493007178192">
<h4>File <cite class="filename">"/usr/local/lib/python2.7/dist-packages/flask/json.py"</cite>,
line <em class="line">237</em>,
in <code class="function">jsonify</code></h4>
<pre>return current_app.response_class(dumps(dict(*args, **kwargs),</pre>
</div>
</ul>
<blockquote>ValueError: dictionary update sequence element #0 has length 3; 2 is required</blockquote>
</div>
<div class="plain">
<form action="/?__debugger__=yes&cmd=paste" method="post">
<p>
<input type="hidden" name="language" value="pytb">
This is the Copy/Paste friendly version of the traceback. <span
class="pastemessage">You can also paste this traceback into
a <a href="https://gist.github.com/">gist</a>:
<input type="submit" value="create paste"></span>
</p>
<textarea cols="50" rows="10" name="code" readonly>Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py", line 271, in error_router
return original_handler(e)
File "/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py", line 271, in error_router
return original_handler(e)
File "/usr/local/lib/python2.7/dist-packages/flask_cors/extension.py", line 188, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py", line 268, in error_router
return self.handle_error(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py", line 271, in error_router
return original_handler(e)
File "/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py", line 271, in error_router
return original_handler(e)
File "/usr/local/lib/python2.7/dist-packages/flask_cors/extension.py", line 188, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py", line 268, in error_router
return self.handle_error(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py", line 477, in wrapper
resp = resource(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flask/views.py", line 84, in view
return self.dispatch_request(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py", line 587, in dispatch_request
resp = meth(*args, **kwargs)
File "/home/ubuntu/workspace/qtaapi/qtaapi/resources/model_exposure_currencies.py", line 198, in get
return jsonify(data)
File "/usr/local/lib/python2.7/dist-packages/flask/json.py", line 237, in jsonify
return current_app.response_class(dumps(dict(*args, **kwargs),
ValueError: dictionary update sequence element #0 has length 3; 2 is required</textarea>
</form>
</div>
<div class="explanation">
The debugger caught an exception in your WSGI application. You can now
look at the traceback which led to the error. <span class="nojavascript">
If you enable JavaScript you can also use additional features such as code
execution (if the evalex feature is enabled), automatic pasting of the
exceptions and much more.</span>
</div>
<div class="footer">
Brought to you by <strong class="arthur">DON'T PANIC</strong>, your
friendly Werkzeug powered traceback interpreter.
</div>
</div>
</body>
</html>
<!--
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py", line 271, in error_router
return original_handler(e)
File "/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py", line 271, in error_router
return original_handler(e)
File "/usr/local/lib/python2.7/dist-packages/flask_cors/extension.py", line 188, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py", line 268, in error_router
return self.handle_error(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py", line 271, in error_router
return original_handler(e)
File "/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py", line 271, in error_router
return original_handler(e)
File "/usr/local/lib/python2.7/dist-packages/flask_cors/extension.py", line 188, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py", line 268, in error_router
return self.handle_error(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py", line 477, in wrapper
resp = resource(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flask/views.py", line 84, in view
return self.dispatch_request(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.5-py2.7.egg/flask_restful/__init__.py", line 587, in dispatch_request
resp = meth(*args, **kwargs)
File "/home/ubuntu/workspace/qtaapi/qtaapi/resources/model_exposure_currencies.py", line 198, in get
return jsonify(data)
File "/usr/local/lib/python2.7/dist-packages/flask/json.py", line 237, in jsonify
return current_app.response_class(dumps(dict(*args, **kwargs),
ValueError: dictionary update sequence element #0 has length 3; 2 is required
-->
ubuntu@ubuntu:~/.ssh$
最佳答案
尝试给 jsonify 提供一个字典:
def get(self):
data = [{"id": "2", "lags": [{"id": "GBPQ1"}, {"id": "GBPQ2"},{"id": "GBPQ3"}, {"id": "BPQ4"}], "name": "GBP"}]
return jsonify({'data': data})
或者如果您愿意,您也可以这样做:return jsonify(data=data)
关于python - Flask 和有效的 json - ValueError : dictionary update sequence element #0 has length 3; 2 is required,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38869273/
我找到了以下代码片段: length = length and length or len(string) 在我看来,这应该等同于: length = length or len(string) 我能
当我使用 numpy.shape() 检查数组的形状时,我有时会得到 (length,1) 有时会得到 (length,)。看起来区别在于列向量与行向量......但它似乎并没有改变数组本身的任何内容
我正在学习 Java,有一个简单的问题。 在设置类的示例中,我看到了这一点: length >= 0 ? length : length * -1 这是什么意思? 谢谢。 最佳答案 这是一种骇人听闻的
我在阅读有关在 Ruby 中重新定义方法有多么容易的文章时遇到了以下问题: class Array alias :old_length :length def length old_l
例如在下面的代码中a和b和c是相等的。 EditText editText; editText = (EditText) findViewById(R.id.edttxt); editText.set
在昨天教授我的 JavaScript 类(class)时,我和我的学生遇到了一些有趣的功能,我认为这些功能可能值得在一个问题和我得出的答案中捕捉到。 在 Chrome 的 JS 控制台中输入 Arra
这个问题在这里已经有了答案: How can I get the size of an array, a Collection, or a String in Java? (3 个回答) 3年前关闭。
这个问题在这里已经有了答案: length and length() in Java (8 个答案) 关闭 6 年前。 我注意到在计算数组的长度时,你会这样写: arrayone.length; 但
console.log(this.slides.length()); 打印 Cannot read property 'length' of undefined.在 setTimeout 为 100
在搜索stackoverflow问题时,我发现了此链接: Error in file.download when downloading custom file。 但是,我的情况有些不同(我认为):
这个问题已经有答案了: Why does R use partial matching? (1 个回答) 已关闭 8 年前。 大家。我刚刚开始使用 swirl 学习 R 编程。 我刚刚了解到seq 。
这个问题已经有答案了: Why does R use partial matching? (1 个回答) 已关闭 8 年前。 大家。我刚刚开始使用 swirl 学习 R 编程。 我刚刚了解到seq 。
这个问题已经有答案了: How can I get the size of an array, a Collection, or a String in Java? (3 个回答) 已关闭 9 年前。
我有一个大数组,其中包含所有类型( bool 值,数组,null,...),并且我正在尝试访问它们的属性arr[i].length,但有些其中显然没有长度。 我不介意那些缺少长度的人是否返回未定义(我
我在对象的属性中有一些文本。我正在测试对象的属性中是否有要显示的文本;如果没有,那么我显示“-”而不是空白。看起来没有什么区别: if (MyObject.SomeText && MyObject.S
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Why is String.length() a method? Java - Array's length
这个问题在这里已经有了答案: obj.length === +obj.length in javascript (4 个答案) 关闭 9 年前。 我一直在读underscore.js源代码并在 _.
#include using std::cout; using std::cin; using std::string; int main(){ cout > name; cout
我正在细读 underscore.js annotated source当我遇到这个时: if (obj.length === +obj.length) {...} 我现在从this stackove
我正在查看 dotnet 运行时中的一些代码,我注意到不是这样写的: if (args.Length > 0) 他们使用这个: if (args is { Length: > 0}) 你知道用第二种方
我是一名优秀的程序员,十分优秀!