urllib2 - My POST Request just isn't working right

Fredrik Lundh fredrik at pythonware.com
Wed Feb 1 11:45:01 EST 2006


Gregory Piñero wrote:

> 1 . One thing that is weird is that the data part just says "Your
> FedEx Transaction".  I know I put the XML here, but I also notice that
> urllib2 is putting this as:
>
> request=<xml ....
>
> Can I have my xml placed here without that something= part?  That
> don't specify what parameter name I should use.

you told it to do that:

    values = {'request':xml_request}
    data = urllib.urlencode(values)

so if you don't want it, all you have to do is to pass in the transaction
xml instead of the urlencoded form data:

    req = urllib2.Request(FedEx_API_URL, xml_request, headers)

> 2. urllib2 seems to create my request with \n\r line endings.  Should
> it maybe just be \n?  And if so, how to change that?

"\r\n", more likely.  and that's how things should be.

</F>






More information about the Python-list mailing list