-
Notifications
You must be signed in to change notification settings - Fork 2
/
web_access.py
executable file
·49 lines (40 loc) · 1.48 KB
/
web_access.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#
#
# Proxy Server for Local Web Server
#
#
#
#
import urllib
import urllib2
import json
import requests
from requests.auth import HTTPDigestAuth
class Web_Client_Interface():
def __init__( self ):
pass
def get_path( self, path="/", user="admin", password="password"):
if path[0] != '/':
path = "/"+path
url = "http://192.168.1.82"+path
#print "path",path,"url",url
r = requests.get(url, auth=HTTPDigestAuth(user, password))
print "r",r.status_code
return { "success":(requests.codes.ok==r.status_code), "status":r.status_code ,"results": r.text }
def post_path( self, path="/", user="admin", password="password",payload = ""):
if path[0] != '/':
path = "/"+path
#print "post_path ---->",path,payload
url = "http://192.168.1.82"+path
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
r = requests.post(url, json=payload , auth=HTTPDigestAuth(user, password), headers=headers)
return { "success":(requests.codes.ok==r.status_code), "status":r.status_code ,"results": r.json() }
if __name__ == "__main__":
web_client = Web_Client_Interface( )
print web_client.get_path(path="")
json_object = {}
json_object["hash_name"] = "CONTROL_VARIABLES"
json_object["key_list"] = {}
json_object["key_list"]["rain_day"] = 0
x = json.dumps(json_object)
print web_client.post_path(path="/ajax/set_redis_hkeys",payload=json.dumps(json_object))