Completed
Push — master ( 3de2d7...fcfe03 )
by Gus
01:06
created

post_json()   A

Complexity

Conditions 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
import requests
4
import json
5
6
def post_json(service, json_data):
7
    # POST json to the server API
8
    #response = requests.post(service, json={"text":"{}".format(text)})
9
    # for older versions of requests, use the call below
10
    #print("SERVICE: {}".format(service))
11
    response = requests.post(service,
12
                             data=json_data,
13
                             headers={"content-type": "application/json"},
14
                             timeout=None
15
                             )
16
    # response content should be utf-8
17
    content = response.content.decode("utf-8")
18
    #print("CONTENT: {}".format(content))
19
    return json.loads(content)
20