Created
September 9, 2013 18:34
-
-
Save davidchambers/6499651 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
FILES = ( | |
'foo.txt', | |
'bar.txt', | |
'baz.txt', | |
) | |
def getmetadata(path): | |
return {'blah': True, 'quux': 42} | |
def getcontents(path): | |
with open(path, 'rb') as f: | |
return f.read() |
This file contains hidden or 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 base64 | |
import json | |
import urllib2 | |
import common as _ | |
def repr(path): | |
return dict(contents=base64.b64encode(_.getcontents(path)), | |
**_.getmetadata(path)) | |
req = urllib2.Request('http://httpbin.org/post', | |
json.dumps({name: repr(name) for name in _.FILES}), | |
{'Content-Type': 'application/json'}) | |
res = urllib2.urlopen(req) | |
print res.read() |
This file contains hidden or 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 | |
import common as _ | |
res = requests.post('http://httpbin.org/post', | |
data={name: _.getmetadata(name) for name in _.FILES}, | |
files={name: _.getcontents(name) for name in _.FILES}) | |
print res.text |
Author
davidchambers
commented
Sep 9, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment