http - Python post calls are not working -
http - Python post calls are not working -
i have server running @ :
http://localhost:3000/appleconnect
which take post calls. have written python code making http request, doesn't work:
import httplib, urllib, json params = json.load("{'op' : 'sign'}") headers = {"content-type": "application/json", "accept": "text/plain"} conn = httplib.httpconnection("localhost:3000") conn.request("post", "/appleconnect", params, headers) response = conn.getresponse() print response.status, response.reason info = response.read() conn.close()
the above not working. gives me error like:
traceback (most recent phone call last): file "post.py", line 2, in <module> params = json.load("{'op' : 'sign'}") file "/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/json/__init__.py", line 286, in load homecoming loads(fp.read(), attributeerror: 'str' object has no attribute 'read'
where i'm making mistake?
you need utilize json.loads
instead of json.load
. sec error, have create sure string json object first. seek code:
import httplib, urllib, json jsonobject = json.dumps("{'op' : 'sign'}") params = json.loads(jsonobject) ...
python http post
Comments
Post a Comment