PooH
Сделайте минимальный пример, который запускается и выдает этот результат. Если к этому моменту сами не поймете в чем дело, обещаю посмотреть.
SERVER
from werkzeug.wrappers import Request, Response
from werkzeug.serving import run_simple
from jsonrpc import JSONRPCResponseManager, dispatcher
from handlers.base import Base
HOST = 'localhost'
PORT = 80
class Server(Base, Response):
@dispatcher.add_method
def get_detailed_usage(self, service_ref, from_date, to_date):
sql_where = []
sql_vars = []
if service_ref is not None:
sql_where.append("pc.service_ref={}").format(service_ref)
sql_vars.append(service_ref)
if from_date is not None:
sql_where.append("rc.start_time={}").format(from_date)
sql_vars.append(from_date)
if to_date is not None:
sql_where.append("rc.end_time={}").format(to_date)
sql_vars.append(to_date)
# if excludeCallsCoveredByBundleAllowance is not None:
# sql_where.append("excludeCallsCoveredByBundleAllowance={}").format(excludeCallsCoveredByBundleAllowance)
# sql_vars.append(excludeCallsCoveredByBundleAllowance)
sql_query = """
SELECT
pc.customer_ref,
pc.service_ref,
pc.contact_ref,
rc.dnis_ref,
#chair_pin_ref,
#delegate_pin_ref
#chair_pin_number
#delegate_pin_number
pc.username,
rc.end_time,
rc.duration_in_minutes,
rc.billed_duration_in_minutes,
rc.dnis_country_code,
rc.dnis_number,
rc.dnis_in_country_number,
rc.dnis_name,
rc.dnis_type,
rc.is_wwa,
rc.calling_number,
rc.dnis_origin,
rc.is_covered_by_bundle_allowance,
rc.bundle_allowance_type,
rc.bundle_allowance_id,
pc.first_name,
pc.last_name,
pc.email,
rc.pin_booking_chairman,
rc.pin_booking_by
FROM real_time_rating.pin_contact pc
JOIN real_time_rating.rated_cdrs rc
ON ( pc.pin_ref = rc.pin_ref )
"""
if sql_where:
sql_query += " WHERE" + " AND ".join(sql_where)
cursor = self.conn.cursor()
cursor.execute(sql_query, *sql_vars)
result = cursor.fetchall()
return dict(result)
@dispatcher.add_method
def get_summary_usage(self, service_ref, from_date, to_date):
sql_where = []
sql_vars = []
if service_ref is not None:
sql_where.append("pc.service_ref={}").format(service_ref)
sql_vars.append(service_ref)
if from_date is not None:
sql_where.append("rc.start_time={}").format(from_date)
sql_vars.append(from_date)
if to_date is not None:
sql_where.append("rc.end_time={}").format(to_date)
sql_vars.append(to_date)
# if excludeCallsCoveredByBundleAllowance is not None:
# sql_where.append("excludeCallsCoveredByBundleAllowance={}").format(excludeCallsCoveredByBundleAllowance)
# sql_vars.append(excludeCallsCoveredByBundleAllowance)
sql_query = """
SELECT
rc.dnis_in_country_number,
rc.dnis_country_code,
rc.dnis_type,
SUM(rc.duration_in_minutes),
rc.call_charge,
rc.rate_currency_code,
rc.rate_per_minute
FROM real_time_rating.pin_contact pc
JOIN real_time_rating.rated_cdrs rc
ON ( pc.pin_ref = rc.pin_ref )
"""
if sql_where:
sql_query += " WHERE" + " AND ".join(sql_where)
cursor = self.conn.cursor()
cursor.execute(sql_query, *sql_vars)
result = cursor.fetchall()
return dict(result)
@Request.application
def application(self, request):
response = JSONRPCResponseManager.handle(request.data, dispatcher)
return Response(response.json, response.http_status, mimetype='application/json')
if __name__ == '__main__':
server = Server(Base)
run_simple(HOST, PORT, server.application())
CLIENT
import requests
import json
# from exeptions import EndPointConnection
class Client(object):
def get_response(self):
url = 'http://localhost:80'
# headers = {'content-type': 'application/json'}
data = {
"jsonrpc": "2.0",
"method": "get_detailed_usage",
"params": [{"serviceRef": "1234", "fromDate": "2017-01-01 00:00:00", "toDate": "2017-01-31 23:59:59"}],
}
response = requests.get(url, data=json.dumps(data))
# if int(response.status_code) == 200:
# response.json()
# else:
# raise EndPointConnection('Endpoint "{}" not connected.\n\rHTTP-Error {}'.format(url, response.status_code))
return response
if __name__ == "__main__":
result = Client()
print(result.get_response())
Запускаю клиент - получаю Response 200 и всё.