[Tutor] Drifting Values in urllib.

doug shawhan doug.shawhan at gmail.com
Sun May 7 00:23:16 CEST 2006


I am having difficulty inderstanding urllib's handling of values passed to
it.

I assign values from cgi.FieldStorage() thusly:


if form.has_key("id"):
    id = form["id"].value

if form.has_key("origin"):
    origin = form["origin"].value

if form.has_key("dest"):
    dest = form["dest"].value
 -----

and so on.

I then attempt to pass the values to urllib.urlencode():

 parameters = urllib.urlencode
({"id":"%s","origin":"%s","dest":"%s","class1":"85","weight1":"185","custdata":"%s","respickup":"","resdel":"%s","insidechrg":"","furnchrg":"","cod":""})%(id,origin,dest,custdata,resdel)

which rewards me with an error from the remote server.

I then print the parameters value to see what is going on:

origin= 8002886787&insidechrg=&respickup=&dest= 47720&resdel=
47567&custdata= Goat Kamal&cod=&weight1=185&furnchrg=&id=X&class1=85

Hmmm.. not at all what I put in! :-)

I checked just to make sure my assignments were correct in the first place:

 print
'''"id":"%s","origin":"%s","dest":"%s","class1":"85","weight1":"185","custdata":"%s","respickup":"","resdel":"%s","insidechrg":"","furnchrg":"","cod":""'''%(id,origin,dest,custdata,resdel)

which reaps:

"id":"8002886787","origin":"47720","dest":"47567","class1":"85","weight1":"185","custdata":"GoatKamal","respickup":"","resdel":"X","insidechrg":"","furnchrg":"","cod":""

Am I missing something fundamental here? I am not used to dictionaries
swirling around like this. :-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060506/9ae12298/attachment.html 


More information about the Tutor mailing list