blob: b0164d4c001fbc9090c12264d92b65e1ac636ab4 (
plain)
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
|
# -*- encoding:utf-8 -*-
import json
import codecs
import urllib2
def byteify(input):
if isinstance(input, dict):
return {byteify(key):byteify(value) for key,value in input.iteritems()}
elif isinstance(input, list):
return [byteify(element) for element in input]
elif isinstance(input, unicode):
return input.encode('utf-8')
else:
return input
token = '0232f37f8e1726684516434441af745'
BASE_URL = 'http://140.211.168.111:8080/'
# BASE_URL = 'http://127.0.0.1:8000/'
PATH_URL = 'upload/'
url = BASE_URL + PATH_URL
def http_post(url, data, token):
postdata = data
post = []
post.append(postdata)
req = urllib2.Request(url, json.dumps(post))
access_token = token
req.add_header('Authorization', access_token) # add token in header
req.add_header('Content-Type', 'application/json')
response = urllib2.urlopen(req)
result = json.loads(response.read())
print result.encode('utf-8')
with open("./results.json",'r') as load_f:
load_dict = (json.load(load_f, encoding="UTF-8"))
http_post(url,load_dict,token)
# for line in s:
# print line.encode('utf-8')
|