Skip to content

Instantly share code, notes, and snippets.

@jmwenda
Last active August 29, 2015 14:04
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 jmwenda/59162d2a223862a604b9 to your computer and use it in GitHub Desktop.
Save jmwenda/59162d2a223862a604b9 to your computer and use it in GitHub Desktop.
ODK Form Post
import requests
from requests.auth import HTTPDigestAuth
#this is a series of scripts to help in testing ODK Aggregate requests
print "Beggining of processing"
#we begin testing to see if we can get odk forms
r = requests.get('https://promisetracker.appspot.com/formList')
#lets perfom and ODK authentication
#url = 'http://localhost:8080/ODKAggregate/formUpload'
url = 'https://promisetracker.appspot.com/formUpload'
files = {'form_def_file': open('/Users/jude/Downloads/Birds.xml', 'rb')}
r = requests.post(url, files=files,auth=('Jude','mwenda'))
req = requests.Request('POST',url,files=files)
prepared = req.prepare()
def pretty_print_POST(req):
"""
At this point it is completely built and ready
to be fired; it is "prepared".
However pay attention at the formatting used in
this function because it is programmed to be pretty
printed and may differ from the actual request.
"""
print('{}\n{}\n{}\n\n{}'.format(
'-----------START-----------',
req.method + ' ' + req.url,
'\n'.join('{}: {}'.format(k, v) for k, v in req.headers.items()),
req.body,
))
pretty_print_POST(prepared)
import pdb;pdb.set_trace()
print r.status_code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment