<code class="language-python3"><span class="k">def</span> <span class="nf">make_response</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rv</span><span class="p">):</span>
<span class="o">...</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">rv</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">response_class</span><span class="p">):</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">rv</span><span class="p">,</span> <span class="p">(</span><span class="n">text_type</span><span class="p">,</span> <span class="nb">bytes</span><span class="p">,</span> <span class="nb">bytearray</span><span class="p">)):</span>
<span class="n">rv</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">response_class</span><span class="p">(</span><span class="n">rv</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="n">headers</span><span class="p">,</span> <span class="n">status</span><span class="o">=</span><span class="n">status</span><span class="p">)</span>
<span class="n">headers</span> <span class="o">=</span> <span class="n">status</span> <span class="o">=</span> <span class="k">None</span>
<span class="c"># rv是 method handle返回的结果,在k神代码中是 <type></type></span>
<span class="k">else</span><span class="p">:</span>
<span class="n">rv</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">response_class</span><span class="o">.</span><span class="n">force_type</span><span class="p">(</span><span class="n">rv</span><span class="p">,</span> <span class="n">request</span><span class="o">.</span><span class="n">environ</span><span class="p">)</span>
</code>
因为type(data)返回的是一个type类型,而函数不允许return一个type类型。改成这样:
return repr(type(data))
可能是机制不一样,flask的视图返回字符串之类,就算你返回数字也是不行的,最近我也是在弄微信web那块,刚折腾的差不多,而且你那个公众号好像是个人未认证订阅号吧,开发者模式没有自定义菜单的,也就是缺少一个直接的web入口,还得通过消息发链接,挺麻烦的,限制很多,另外去stackoverflow搜索会更好点,基本都能找到答案
app.debug=True
可以看到详细错误
按规定这个要返回字符串,那你就要返回字符串,返回别的能用不说明任何问题,也不代表以后的版本仍然能用,当你返回不是字符串的时候就已经是未定义行为了,只是在web.py里面这个未定义行为刚好是可以用的而已
你可以打开debug模式。
来自 webpy 源码 webpy/utils.py
<code class="language-python"><span class="k">def</span> <span class="nf">safestr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s">'utf-8'</span><span class="p">):</span>
<span class="sd">r"""</span>
<span class="sd"> Converts any given object to utf-8 encoded string. </span>
<span class="sd"> </span>
<span class="sd"> >>> safestr('hello')</span>
<span class="sd"> 'hello'</span>
<span class="sd"> >>> safestr(u'\u1234')</span>
<span class="sd"> '\xe1\x88\xb4'</span>
<span class="sd"> >>> safestr(2)</span>
<span class="sd"> '2'</span>
<span class="sd"> """</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="nb">unicode</span><span class="p">):</span>
<span class="k">return</span> <span class="n">obj</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="n">encoding</span><span class="p">)</span>
<span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
<span class="k">return</span> <span class="n">obj</span>
<span class="k">elif</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s">'next'</span><span class="p">):</span> <span class="c"># iterator</span>
<span class="k">return</span> <span class="n">itertools</span><span class="o">.</span><span class="n">imap</span><span class="p">(</span><span class="n">safestr</span><span class="p">,</span> <span class="n">obj</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="nb">str</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>
</code>
我写的flask应用中,methods是写在app.route装饰器里面的。
类似这样
@app.route('/', methods=['GET', 'POST'])
def func(args):
要不这么改改试试?