Connecting Tech Pros Worldwide Forums | Help | Site Map

urllib.urlencode multidimensional dictionary

Newbie
 
Join Date: Mar 2007
Posts: 15
#1: Mar 6 '09
Hi all,

I am trying to use urllib.urlencode to post a multidimensional dictionary to a php page.

This is the code I am using

Expand|Select|Wrap|Line Numbers
  1. test = {}
  2. test['boom'] = {}
  3. test['boom']['zoom'] = "bang"
  4.  
  5. server_params = urllib.urlencode(test)
  6.  
  7. response = urllib2.urlopen(server_url, server_params).read()
  8.  
And if I do a print of the post variable from php my output is looking like this

Expand|Select|Wrap|Line Numbers
  1. Array
  2. (
  3.     [boom] => {\'zoom\': \'bang\'}
  4. )
  5.  
Only the first key of the dictionary is being preserved while everything underneath is being squished into a string.

Is there a way to preserve the entire structure of the dictionary?

Thanks!

Reply