kartagis / pysimplesoap

Automatically exported from code.google.com/p/pysimplesoap
0 stars 0 forks source link

pycurl header (HTTPHEADER) string list #124

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. use pycurl
2. call webservice with headers

What is the expected output? What do you see instead?
- the call should pass

What version of the product are you using? On what operating system?
- latest 1.10 release

Please provide any additional information below.

exception at transport.py, line 188
c.setopt(pycurl.HTTPHEADER, hdrs)
TypeError: list items must be string objects

I have fixed it by changing the assignement to "hdrs" variable as follows:

hdrs = ['%s: %s' % (str(k), str(v)) for k, v in headers.items()]

It is probably because content length was integer...

Original issue reported on code.google.com by g...@seges.sk on 29 Oct 2013 at 3:13

GoogleCodeExporter commented 8 years ago
This seems to be already patched:

                hdrs = ['%s: %s' % (k, v) for k, v in headers.items()]

https://code.google.com/p/pysimplesoap/source/browse/pysimplesoap/transport.py#2
00

The latest version is currently 1.11, not 1.10

Please download it from the repo:

https://github.com/pysimplesoap/pysimplesoap/archive/master.zip

Let us know if your issue is fixed (wsdl support was enhanced in the 
development version)

Original comment by reingart@gmail.com on 20 Dec 2013 at 8:01

GoogleCodeExporter commented 8 years ago
Issue persist even with the patch you mentioned: 
    hdrs = ['%s: %s' % (k, v) for k, v in headers.items()]

Still raises a TypeError, the only way to make it work is to consistently get 
the string representation for items in the dict (str()). From what I saw in the 
debugger some values in the headers dict come as unicode strings u' ' and some 
as literal strings ' ', which when combined with unicode strings result in a 
new unicode string and it seems the pycurl API expects a literal string.

I'm not entirely sure how this plays out in python 3 since the str type is now 
unicode and python2.7's str is now called bytes.

Seen in: python 2.6, PySimpleSOAP 1.10, pycurl 7.19.0 (could not verify with 
latest 7.19.5)

Original comment by joans34 on 28 Aug 2014 at 5:50

GoogleCodeExporter commented 8 years ago
There should be some implicit unicode conversions.
Can you test the following code?

hdrs = ['%s: %s' % (k, v) for k, v in headers.items()]
hdrs = [hdr.encode('latin1') if isinstance(hdr, unicode) else hdr for hdr in 
hdrs]

TIA

Original comment by reingart@gmail.com on 28 Aug 2014 at 6:22

GoogleCodeExporter commented 8 years ago
That seems to do the trick.

Thanks!

Original comment by joans34 on 28 Aug 2014 at 7:19