Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #18242
| From | Niklas Rosencrantz <niklasro@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | InvalidResponseError: headers must be str |
| Date | 2011-12-30 20:58 -0800 |
| Organization | http://groups.google.com |
| Message-ID | <18871670.1096.1325307490244.JavaMail.geo-discussion-forums@yqdx38> (permalink) |
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
I think it is because somewhere my HTTP headers are cast to unicode instead of string but I can't find where in the code? 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),
}
data = {
'currencyCode': 'USD',
'returnUrl': return_url,
'cancelUrl': cancel_url,
'requestEnvelope': { 'errorLanguage': 'en_US' },
}
if shipping:
data['actionType'] = 'CREATE'
else:
data['actionType'] = 'PAY'
if secondary_receiver == None: # simple payment
data['receiverList'] = { 'receiver': [ { 'email': settings.PAYPAL_EMAIL, 'amount': '%f' % amount } ] }
else: # chained
commission = amount * settings.PAYPAL_COMMISSION
data['receiverList'] = { 'receiver': [
{ 'email': settings.PAYPAL_EMAIL, 'amount': '%0.2f' % amount, 'primary': 'true' },
{ 'email': secondary_receiver, 'amount': '%0.2f' % ( amount - commission ), 'primary': 'false' },
]
}
if ipn_url != None:
data['ipnNotificationUrl'] = str(ipn_url)
self.raw_request = json.dumps(data)
#request = urllib2.Request( "%s%s" % ( settings.PAYPAL_ENDPOINT, "Pay" ), data=self.raw_request, headers=headers )
#self.raw_response = urllib2.urlopen( request ).read()
self.raw_response = url_request( "%s%s" % ( str(settings.PAYPAL_ENDPOINT), str("Pay") ), data=self.raw_request, headers=headers ).content()
logging.info( "response was: %s" % self.raw_response )
self.response = json.loads( str(self.raw_response) )
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
InvalidResponseError: headers must be str Niklas Rosencrantz <niklasro@gmail.com> - 2011-12-30 20:58 -0800
Re: InvalidResponseError: headers must be str Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-31 06:40 +0000
Re: InvalidResponseError: headers must be str Niklas Rosencrantz <niklasro@gmail.com> - 2011-12-31 00:32 -0800
Re: InvalidResponseError: headers must be str Niklas Rosencrantz <niklasro@gmail.com> - 2011-12-31 00:44 -0800
Re: InvalidResponseError: headers must be str Serhiy Storchaka <storchaka@gmail.com> - 2011-12-31 12:04 +0200
Re: InvalidResponseError: headers must be str Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-31 12:52 +0000
Re: InvalidResponseError: headers must be str Niklas Rosencrantz <niklasro@gmail.com> - 2011-12-31 05:31 -0800
Re: InvalidResponseError: headers must be str Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-31 14:31 +0000
Re: InvalidResponseError: headers must be str Niklas Rosencrantz <niklasro@gmail.com> - 2011-12-31 17:40 -0800
Re: InvalidResponseError: headers must be str "Waldek M." <wm@localhost.localdomain> - 2012-01-02 19:18 +0100
csiph-web