Last active
August 29, 2015 14:04
-
-
Save jmwenda/59162d2a223862a604b9 to your computer and use it in GitHub Desktop.
ODK Form Post
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 | |
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