Permalink
Browse files

-Made interface.py compatibile with non-ascii & unicode strings; basi…

…cally we encode everything as UTF-8 before pushing to paypal. If this is not done, then urllib fails the GET url generation.

-Cleaned up debug printing on settings.py
-misc other fixes
  • Loading branch information...
1 parent d7ec9cc commit 52dc2d037824e8a926ed90098abe146ba97027b4 Jonathan Vanasco committed with Jul 13, 2010
Showing with 15 additions and 7 deletions.
  1. +15 −5 paypal/sdk/interface.py
  2. +0 −2 paypal/sdk/settings.py
View
@@ -10,6 +10,7 @@
from response import Response
from exceptions import ApiError
+import types
def _check_required( requires , **kwargs ):
for req in requires :
@@ -18,6 +19,13 @@ def _check_required( requires , **kwargs ):
raise ApiError('missing required : %s' % req )
+def encode_utf8( **kwargs ):
+ u2= kwargs
+ for i in u2.keys():
+ if isinstance( u2[i] , types.UnicodeType ):
+ u2[i]= u2[i].encode('utf-8')
+ return u2
+
class Interface(object):
@@ -69,8 +77,9 @@ def call( self , method , **kwargs ):
for i in k:
print " %-20s : %s" % ( i , urlvalues[i] )
-
- data = urllib.urlencode(urlvalues)
+ u2= encode_utf8( **urlvalues )
+
+ data = urllib.urlencode(u2)
req = urllib2.Request( self.config.API_ENDPOINT , data , headers )
response = Response( urllib2.urlopen(req).read() , self.config )
@@ -298,7 +307,8 @@ def generate_cart_upload_redirect_url( self, **kwargs ):
&upload=1
"""
_check_required( ('business','item_name_1','amount_1','quantity_1') , **kwargs )
- url= "%s?cmd=_cart&upload=1&" % ( self.config.PAYPAL_URL_BASE )
- additional= urllib.urlencode(kwargs)
- url= url + additional
+ url= "%s?cmd=_cart&upload=1" % ( self.config.PAYPAL_URL_BASE )
+ additional= encode_utf8( **kwargs )
+ additional= urllib.urlencode(additional)
+ url= url + "&" + additional
return url
View
@@ -54,8 +54,6 @@ class PayPalConfig(object):
def __init__(self, **kwargs):
- print kwargs
-
if 'API_ENVIRONMENT' not in kwargs:
kwargs['API_ENVIRONMENT']= self.API_ENVIRONMENT
if kwargs['API_ENVIRONMENT'] not in self._valid_['API_ENVIRONMENT']:

0 comments on commit 52dc2d0

Please sign in to comment.