InvalidResponseError: headers must be str
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Dec 31 01:40:42 EST 2011
On Fri, 30 Dec 2011 20:58:10 -0800, Niklas Rosencrantz wrote:
> I'm upgrading from python 2.5 to python 2.7 and then I'm starting to get
> this error:
>
> InvalidResponseError: headers must be str
Please show the ENTIRE traceback, not just the error message. The
traceback is very informative: it shows the actual line of code that
causes the problem, plus the entire sequence of calls that lead to it.
The error message on its own is almost useless.
Please COPY AND PASTE the traceback, do not re-type it from memory,
summarize it, simplify it, or otherwise change it in any way.
> I think it is because somewhere my HTTP headers are cast to unicode
Why do you think that?
> instead of string but I can't find where in the code?
Have you tried searching for any of these?
- direct calls to unicode()
- unicode literals u"..."
- calls to the decode method some_string.decode( ... )
> The example code
> I'm trying to upgrade to python 2.7 is
> https://github.com/supernifty/gae-paypal-online-market-example
>
> class Pay( object ):
> def __init__( self, amount, return_url, cancel_url, remote_address,
> secondary_receiver=None, ipn_url=None, shipping=False ):
> headers = {
> 'X-PAYPAL-SECURITY-USERID': str(settings.PAYPAL_USERID),
> 'X-PAYPAL-SECURITY-PASSWORD': str(settings.PAYPAL_PASSWORD),
> 'X-PAYPAL-SECURITY-SIGNATURE': str(settings.PAYPAL_SIGNATURE),
> 'X-PAYPAL-REQUEST-DATA-FORMAT': str('JSON'),
> 'X-PAYPAL-RESPONSE-DATA-FORMAT': str('JSON'),
> 'X-PAYPAL-APPLICATION-ID': str(settings.PAYPAL_APPLICATION_ID),
> 'X-PAYPAL-DEVICE-IPADDRESS': str(remote_address),
> }
'JSON' is already a string. Calling str() on it is a waste of time.
What values do the various settings.* have? If they are already strings,
calling str() again is a waste of time. I see you do this all through
your class, needlessly calling str() on strings.
--
Steven
More information about the Python-list
mailing list