Skip to content

Instantly share code, notes, and snippets.

@blackrobot
Created October 1, 2011 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blackrobot/1256370 to your computer and use it in GitHub Desktop.
Save blackrobot/1256370 to your computer and use it in GitHub Desktop.
making an xml request, and turning it into xml
>>> 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