Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python newbody=ntob(';';)。联接(newbody)类型错误:序列项1:预期字符串,找到int_Python_Cherrypy - Fatal编程技术网

Python newbody=ntob(';';)。联接(newbody)类型错误:序列项1:预期字符串,找到int

Python newbody=ntob(';';)。联接(newbody)类型错误:序列项1:预期字符串,找到int,python,cherrypy,Python,Cherrypy,解决此错误的最佳方法是什么? TypeError:序列项1:应为字符串,找到int python文件(回溯中未提及)是500行 Request Headers: COOKIE: admin_sess=c13d2f729d47c132b223e8f19ce77ac25aa12 ORIGIN: https://192.168.1.135:5001 Remote-Addr: 192.168.1.161 Content-Length: 36 USER-AGENT: Mozilla/5

解决此错误的最佳方法是什么? TypeError:序列项1:应为字符串,找到int

python文件(回溯中未提及)是500行

Request Headers:
  COOKIE: admin_sess=c13d2f729d47c132b223e8f19ce77ac25aa12
  ORIGIN: https://192.168.1.135:5001
  Remote-Addr: 192.168.1.161
  Content-Length: 36
  USER-AGENT: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/43.0.2357.81 Chrome/43.0.2357.81 Safari/537.36
  CONNECTION: keep-alive
  REFERER: https://192.168.1.135:5001/
  X-REQUESTED-WITH: XMLHttpRequest
  HOST: 192.168.1.135:5001
  ACCEPT: */*
  ACCEPT-LANGUAGE: en-US,en;q=0.8
  Content-Type: application/x-www-form-urlencoded; charset=UTF-8
  ACCEPT-ENCODING: gzip, deflate
[18/Jun/2015:18:10:15] HTTP Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 661, in respond
    response.finalize()
  File "/usr/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 927, in finalize
    content = self.collapse_body()
  File "/usr/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 894, in collapse_body
    newbody = ntob('').join(newbody)
TypeError: sequence item 1: expected string, int found

str.join
函数需要一个字符串序列,但您的
newbody
中至少有一项是
int
。首先尝试将它们转换为字符串:

newbody = ntob('').join(map(str, newbody))

通常,最好还提供一个代码片段来重现问题。你的问题很清楚。你在做一些类似于:

class App:

  @cherrypy.expose
  def index(self):
    return (0xdeadbeaf,)

  @cherrypy.expose
  def also(self):
    yield 0xdeadbeaf
CherryPy处理程序应该返回(yield)
str
unicode
字节
或其中的一部分。还可以返回类似文件的对象。不能返回其他类型,如
int
或带有
int
项的序列