Last active
December 17, 2015 06:49
-
-
Save psychok7/5568291 to your computer and use it in GitHub Desktop.
Python Post to REST API using Basic Authentication
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 urllib2, json | |
def post(): | |
def basic_authorization(user, password): | |
s = user + ":" + password | |
return "Basic " + s.encode("base64").rstrip() | |
data = json.dumps({'username':'david2', 'email':'[email protected]' , 'password':'mypassword'}) | |
req = urllib2.Request("http://192.168.1.77:8080/api/stats/user/", | |
headers = {"Authorization": basic_authorization("y", "y"),"Content-Type": "application/json"}, | |
data = data | |
) | |
#req.get_method = lambda: 'PUT' | |
f = urllib2.urlopen(req) | |
post() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment