简体   繁体   English

创建一个Python Web服务器以接收XML HTTP请求

[英]Creating a python web server to recieve XML HTTP Requests

I am currently working on a project to create simple file uploader site that will update the user of the progress of an upload. 我目前正在开发一个创建简单文件上传器网站的项目,该网站将向用户更新上传进度。

I've been attempting this in pure python (with CGI) on the server side but to get the progress of the file I obviously need send requests to the server continually. 我一直在服务器端使用纯python(使用CGI)进行尝试,但是要获得文件的进度,我显然需要不断地向服务器发送请求。 I was looking to use AJAX to do this but I was wondering how hard it would be to, instead of changing to some other framerwork (web.py for instance), just write my own web server for receiving the XML HTTP Requests? 我一直想使用AJAX来做到这一点,但我想知道这样做有多困难,而不是更改为其他框架(例如web.py),而是编写我自己的Web服务器来接收XML HTTP请求?

My main problem is that sending the request is done from HTML and Javascript so it all seems like magic trickery at the moment. 我的主要问题是,发送请求是通过HTML和Javascript完成的,因此目前看来,这似乎是魔术。

Can anyone advise me as to the best way to go about receiving these requests on the server? 有人可以建议我在服务器上接收这些请求的最佳方法吗?

EDIT: It seems that a framework would be the way to go. 编辑:似乎框架是要走的路。 Would web.py be a good route to take? web.py将是一个不错的选择吗?

I would recommend to use a microframework like Sinatra for Ruby. 我建议为Ruby使用类似Sinatra的微框架。 There seem to be some equivalents for Python. 似乎有一些Python等效项。 What python equivalent of Sinatra would you recommend? 您会推荐什么等同于Sinatra的python?

Such a framework allows you to simply map a single method to a route. 这样的框架使您可以简单地将单个方法映射到路由。

Writing a very basic HTTP server won't be very hard (see http://docs.python.org/library/simplehttpserver.html for an example), but you will be missing many features that are provided by real servers and web frameworks. 编写非常基本的HTTP服务器并不难(例如,请参见http://docs.python.org/library/simplehttpserver.html ),但是您将缺少实际服务器和Web框架提供的许多功能。 。

For your project, I suggest you pick one of the many Python web frameworks and run your application behind Apache/mod_wsgi. 对于您的项目,建议您选择许多Python Web框架之一,并在Apache / mod_wsgi之后运行应用程序。

There's absolutely no need to write your own web server. 绝对不需要编写自己的Web服务器。 Plenty of options exist, including lightweight ones like nginx. 存在很多选项,包括诸如nginx之类的轻量级选项。

You should use one of those, and either your own custom WSGI code to receive the request, or (better) one of the microframeworks like Flask or Bottle. 您应该使用其中之一,或者使用自己的自定义WSGI代码来接收请求,或者(最好)使用诸如Flask或Bottle的微框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM