By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,382 Members | 2,058 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,382 IT Pros & Developers. It's quick & easy.

urllib2 - My POST Request just isn't working right

P: n/a
Hi guys,

I'm trying to write a program to get FedEx shipping rates, and I'm
following their API as outlined in this document:

I need specifically to make a POST request to their server as shown on
page 12. However I continually get server error 500, and they FedEx
support advised me that this means my request is incorrect somewhere.

I put the code I"m using at the end of this email. Unfortunately I
don't know how to "see" the request the code generates either so I
can't paste that here.

Any help would be greatly appriciated.

Gregory Piñero
Chief Innovation Officer
Blended Technologies

Code pasted below (contains sample info so it won't work for you):

import urllib
import urllib2


xml_request="""<?xml version="1.0" encoding="UTF-8" ?>
<FDXSubscriptionRequest xmlns:api=""
xsi:noNamespaceSchemaLocation="FDXSubscriptionRequ est.xsd">
<PersonName>Jim Smith</PersonName>
<CompanyName>Creative Widgets</CompanyName>
<Line1>123 Main Street</Line1>
<Line2>1st Floor</Line2>

values = {'request':xml_request}
headers = { 'Referer' : 'YourCompany',
'Accept':'image/gif, image/jpeg, image/pjpeg, text/plain,
text/html, */*',

data = urllib.urlencode(values)
req = urllib2.Request(FedEx_API_URL, data, headers)
handle = urllib2.urlopen(req)
except IOError, e:
if hasattr(e, 'reason'):
print 'We failed to reach a server.'
print 'Reason: ', e.reason
elif hasattr(e, 'code'):
print 'The server couldn\'t fulfill the request.'
print 'Error code: ', e.code
the_page =
print the_page
Feb 1 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a
( gives the same error if you don't .strip() your password
before using it to connect)

i noticed one spelling mistake here:
headers = { 'Referer' : 'YourCompany',


could it be that simple?
Feb 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.