Created
October 1, 2011 17:28
-
-
Save blackrobot/1256370 to your computer and use it in GitHub Desktop.
making an xml request, and turning it into xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import requests # http://python-requests.org | |
>>> headers = {'User-Agent': "Public App ID Goes Here/1.0", 'X-PAPPID': "private.app.id.goes.here"} | |
>>> response = requests.get('http://10.0.23.10:9630/api/invoices/', headers=headers, auth=("username", "password")) | |
# Or for a post, just change the .get to a .post/.put/.delete ... | |
>>> data = {'here': "is", 'my': "data", 'for': "posting"} | |
>>> response = requests.post('http://10.0.23.10:9630/api/invoices/', data=data, headers=headers, auth=("username", "password")) | |
# Now to decode the response xml to python | |
>>> from BeautifulSoup import BeautifulStoneStoup as BSS | |
>>> soup = BeautifulStoneStoup(response) | |
>>> invoices = [] | |
>>> for x in soup.findAll('invoice'): | |
>>> invoices.append(dict((t.name, t.text) for t in x.findAll(True))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment