[OT] Python Q: expected string, tuple found

Lloyd Kvam python at venix.com
Fri Feb 21 08:36:41 EST 2014


  File "/usr/local/lib/python2.7/httplib.py", line 924, in putheader
    str = '%s: %s' % (header, '\r\n\t'.join(values))
TypeError: sequence item 0: expected string, tuple found

I suspect the error is coming from .join(values)
join expects a sequence of strings.  I think it is grumbling that the
first item in values is really a tuple.


Going by the method name (putheader), I would guess that the request
contains a defective header.  However looking at the log and the code, I
do not see the problem...

On Thu, 2014-02-20 at 17:25 -0500, Greg Rundlett (freephile) wrote:
> I'm trying to run a python script called crucible.py (from Atlassian,
> for their Crucible product.)   While I'm waiting for their support, I
> wanted to ask here for help understanding python.
> 
> 
> The script is supposed to setup a code review for a local subversion
> working copy, but it can't even login to the Crucible server.  Using
> the --debug flag, here is what I get:
> 
> 
> 
> 
> grundlett at build-svr1:~/work/test/projects/web/trunk$ crucible.py -r
> test -d
> Crucible server: http://atlassian-demo:8060
> Crucible username: grundlett
> Please enter your Crucible password: 
> DEBUG:root:No authtoken, trying to get one
> DEBUG:root:Trying to encode str as UTF-8
> DEBUG:root:RestRequest:
> http://atlassian-demo:8060/rest-service/auth-v1/login -
> {'Content-Type': 'application/x-www-form-urlencoded', 'Authorization':
> '++SANITIZED++', 'Accept': 'application/json'} -
>  userName=grundlett&password=++SANITIZED++
> DEBUG:root:Traceback (most recent call last):
>   File "/home/grundlett/bin/crucible.py", line 493, in _request
>     response =
> urllib2.build_opener(HTTPRedirectHandler()).open(request,
> data=payload, timeout=self.timeout).read()
>   File "/usr/local/lib/python2.7/urllib2.py", line 391, in open
>     response = self._open(req, data)
>   File "/usr/local/lib/python2.7/urllib2.py", line 409, in _open
>     '_open', req)
>   File "/usr/local/lib/python2.7/urllib2.py", line 369, in _call_chain
>     result = func(*args)
>   File "/usr/local/lib/python2.7/urllib2.py", line 1173, in http_open
>     return self.do_open(httplib.HTTPConnection, req)
>   File "/usr/local/lib/python2.7/urllib2.py", line 1142, in do_open
>     h.request(req.get_method(), req.get_selector(), req.data, headers)
>   File "/usr/local/lib/python2.7/httplib.py", line 946, in request
>     self._send_request(method, url, body, headers)
>   File "/usr/local/lib/python2.7/httplib.py", line 986, in
> _send_request
>     self.putheader(hdr, value)
>   File "/usr/local/lib/python2.7/httplib.py", line 924, in putheader
>     str = '%s: %s' % (header, '\r\n\t'.join(values))
> TypeError: sequence item 0: expected string, tuple found
> 
> 
> So, somewhere a tuple is not being converted to string.  Not sure if
> it's the headers, or extra payload since the log message is sanitized
> by the logger.  The script is http://pastebin.com/3zeYm2qC and line
> 493 is where the problem starts.  Any suggestions?
> 
> 
> I think I could do something like 
> 
> 
> values = ','.join(str(value_list)[1:-1])
> 
> 
> 
> but I'm not sure how, and I'm pretty sure that it's the code in
> crucible.py that is the problem, not in httplib.py
> 
> Greg Rundlett
> http://eQuality-Tech.com
> http://freephile.org
> _______________________________________________
> gnhlug-discuss mailing list
> gnhlug-discuss at mail.gnhlug.org
> http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/

-- 
Lloyd Kvam
Venix Corp
DLSLUG/GNHLUG library
http://dlslug.org/library.html
http://www.librarything.com/catalog/dlslug
http://www.librarything.com/catalog/dlslug&sort=stamp
http://www.librarything.com/rss/recent/dlslug



More information about the gnhlug-discuss mailing list