newbody = ntob('').join(newbody) TypeError: sequence item 1: expected string, int found

341 views Asked by At

What is the best way to troubleshoot this error? TypeError: sequence item 1: expected string, int found

The python file (not mentioned in the traceback) is 500 lines.

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
2

There are 2 answers

0
Tuan Anh Hoang-Vu On

The str.join function expects a sequence of string, but at least one item in your newbody is int. Try to cast them to string first:

newbody = ntob('').join(map(str, newbody))
0
saaj On

Generally it is a good idea to also provide a code snippet that reproduces the issue. With your question it's clear though. You're doing something like:

class App:

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

  @cherrypy.expose
  def also(self):
    yield 0xdeadbeaf

CherryPy handler should return (yield) str, unicode, bytes or iterable of them. Also you can return file-like objects. You can't return other types, like int or sequence with int items.