Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何重写python jsronrpc2应用程序,使其能够作为wsgi应用程序运行_Python_Json_Flask_Wsgi_Json Rpc - Fatal编程技术网

如何重写python jsronrpc2应用程序,使其能够作为wsgi应用程序运行

如何重写python jsronrpc2应用程序,使其能够作为wsgi应用程序运行,python,json,flask,wsgi,json-rpc,Python,Json,Flask,Wsgi,Json Rpc,我在理解用python jsonrpc2编写的应用程序与wgsi应用程序的关系时遇到了一些问题 我在一个名为greeting.py的文件中有一个json rpc测试应用程序 这是一个简单的测试用例 def hello(name=None,greeting=None): # Print to stdout the greeting result = "From jsonrpc you have: {greeting} , {name}".format(greeting=greet

我在理解用python jsonrpc2编写的应用程序与wgsi应用程序的关系时遇到了一些问题

我在一个名为greeting.py的文件中有一个json rpc测试应用程序

这是一个简单的测试用例

def hello(name=None,greeting=None):
    # Print to stdout the greeting
    result =  "From jsonrpc you have: {greeting} , {name}".format(greeting=greeting,name=name)
    # print result
    # You can basically now return the string result
    return  result
我能够将json发布到这个函数,然后返回json响应

样本职位:

 self.call_values_dict_webpost = dict(zip(["jsonrpc","method","id","params"],["2.0","greeting.hello","2",["Hari","Hello"]]))
作为json返回的响应:

u"jsonrpc": u"2.0", u"id": u"2", u"result": u"From jsonrpc you have: Hello , Hari"
我使用jsonrpc2模块中定义的入口点启动服务器,该入口点基本上执行以下操作

from jsonrpc2 import JsonRpcApplication
from wsgiref.simple_server import make_server
app = JsonRpcApplication()
app.rpc.add_module("greeting")
httpd = make_server(host, port, app)
httpd.serve_forever()
我目前可以将这个jsonrpc2服务器作为一个独立的“web应用程序”运行,并对其进行适当的测试

我想了解如何从这个简单的功能web应用程序转变为一个wsgi web应用程序,该应用程序可以在不使用flask或django等web框架的情况下读取和写入json(我知道一些)


我在寻找是否有一个简单的概念性步骤使我的上述函数与wsgi“可调用”兼容:或者我最好使用flask或django来读取/接收json“POST”并编写json响应。

我不知道那个特定的模块,但看起来你的
应用程序
对象就是wsgi应用程序。代码中的所有操作都是实例化应用程序,然后通过wsgiref为其创建服务器。因此,不要这样做,只需将您真正的WSGI服务器—Apache/mod_WSGI或gunicorn,或其他任何东西—指向
应用程序
对象,方式与为Flask或Django提供服务的方式完全相同。

谢谢,多亏了您的回复,我终于找到了答案。我必须用uwsgi--http:9090--wsgi文件wsgi.py--callable app启动服务器。我创建的文件“wsgi.py”的代码与上面提到的入口点代码相同。