精华内容
下载资源
问答
  • python3搭建web服务器

    千次阅读 2019-09-27 11:23:51
    'simple_means_flag': '3' } data = urllib.parse.urlencode(values).encode('utf-8') request = urllib.request.Request(url, data, headers) html = urllib.request.urlopen(request).read().decode('utf-8') ...

    发送http请求

    import urllib.request
    import os
    
    #http代理
    #os.environ['http_proxy'] = 'http://127.0.0.1:8080'
    #os.environ['https_proxy'] = 'https://127.0.0.1:8080'
    
    url = 'http://fanyi.baidu.com/v2transapi'
    headers = {
        'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
    }
    values = {
        'from': 'zh',
        'to': 'en',
        'query': '死肥猪',
        'transtype': 'translang',
        'simple_means_flag': '3'
    }
    data = urllib.parse.urlencode(values).encode('utf-8')
    request = urllib.request.Request(url, data, headers)
    html = urllib.request.urlopen(request).read().decode('utf-8')
    print(html)
    
    

    服务器

    # -*- coding: utf-8 -*-
    """
    Created on Fri Jun 23 08:13:43 2017
    @author: dc
    """
    
    import http.server as hs
    import sys, os
    
    
    class ServerException(Exception):
        '''服务器内部错误'''
    
        pass
    
    
    class RequestHandler(hs.BaseHTTPRequestHandler):
    
        def send_content(self, page, status=200):
    
            self.send_response(status)
            self.send_header("Content-type", "text/html")
            self.send_header("Content-Length", str(len(page)))
            self.end_headers()
            self.wfile.write(bytes(page, encoding='utf-8'))
            # print(page)
    
        def do_GET(self):
            print("---doget")
            self.handle_file("my_fullpath")
            # 这里要处理两个异常,一个是读入路径时可能出现的异常,一个是读入路径后若不是文件,要作为异常处理
            # try:
            #     # 获取文件路径
            #     full_path = os.getcwd() + self.path
            #     # 如果路径不存在
            #     if not os.path.exists(full_path):
            #         raise ServerException("'{0}' not found".format(self.path))
            #     # 如果该路径是一个文件
            #     elif os.path.isfile(full_path):
            #         self.handle_file(full_path)
            #     # 如果该路径不是一个文件
            #     else:
            #         raise ServerException("Unknown object '{0}'".format(self.path))
            # except Exception as msg:
            #
            #     self.handle_error(msg)
    
        def handle_file(self, full_path):
            print("---handle_file")
            self.send_content("---youok" + full_path, 200)
    
            #
            # try:
            #     with open(full_path, 'r') as file:
            #         content = file.read()
            #     self.send_content(content, 200)
            # except IOError as msg:
            #     msg = "'{0}' cannot be read: {1}".format(self.path, msg)
            #     self.handle_error(msg)
    
        Error_Page = """\
        <html>
        <body>
        <h1>Error accessing {path}</h1>
        <p>{msg}</p>
        </body>
        </html>
        """
    
        def handle_error(self, msg):
    
            content = self.Error_Page.format(path=self.path, msg=msg)
    
            self.send_content(content, 404)
    
    
    if __name__ == '__main__':
        httpAddress = ('', 8080)
        httpd = hs.HTTPServer(httpAddress, RequestHandler)
        httpd.serve_forever()

     

    展开全文
  • {"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],"search_count":[{"count_phone":6,"count":6}]},"card":[{"des":"云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT ...

    {"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],"search_count":[{"count_phone":6,"count":6}]},"card":[{"des":"云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。","link1":"https://ecs-buy.aliyun.com/wizard#/prepay/cn-hangzhou","link":"https://www.aliyun.com/product/ecs","icon":"https://img.alicdn.com/tfs/TB1afahQpXXXXaAapXXXXXXXXXX-114-114.png","btn2":"了解价格","tip":"ECS精选产品特惠低至0.95折,立即查看 高配云服务器免费试用,立即查看","btn1":"立即开通","link2":"https://www.aliyun.com/price/product?spm=5176.8789780.1092586.1.2e8e57a8lGNDpl#/ecs/detail","title":"云服务器 ECS"}],"search":[{"txt":"云服务器精选特惠,低至0.95折","link":"https://www.aliyun.com/daily-act/ecs/activity_selection"},{"txt":"ECS新产品s6首发特惠","link":"https://www.aliyun.com/daily-act/ecs/s6_sales"},{"txt":"ECS免费试用最高12个月","link":"https://www.aliyun.com/daily-act/ecs/free"},{"txt":"ECS云服务器学习路径","link":"https://help.aliyun.com/learn/learningpath/ecs.html"},{"txt":"ECS云服务器入门","link":"https://help.aliyun.com/document_detail/25422.html"},{"txt":"ECS云服务器选型推荐","link":"https://help.aliyun.com/document_detail/58291.html"}],"countinfo":{"search":{"length_pc":0,"length":0},"card":{"length_pc":0,"length":0}},"simplifiedDisplay":"newEdition","newCard":[{"link":"https://www.aliyun.com/product/ecs","icon":"ecs","title":"云服务器ECS","des":"云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。","btn1":"产品详情页","btn2":"ECS控制台","btn3":"在线咨询","link3":"https://ai.alimebot.taobao.com/intl/index.htm?from=bg778QBnk9&_user_access_token=Nm9Vb2FMUTBNMXQydUQybXRKcXFUWU52TDhnOS9yN1hRM0JjRURxaGJyNERramxUWGNMSFRENExQUnJ1RXF5K0tHTXFzbmpZL0xWS2pPN24xSVVpeHNrM2tGTVVjQXFvYnlkN09JcklrMFhLZllCTnpLbTRGKzZyME4vd3hkQzdxbjl6SnZ3YnR6MlJTdkh2cGJTc1ZRPT0=","link1":"https://www.aliyun.com/product/ecs","link2":"https://ecs.console.aliyun.com/#/home","infoGroup":[{"infoName":"最新活动","infoContent":{"firstContentName":"云服务器低至0.95折","firstContentLink":"https://www.aliyun.com/daily-act/ecs/activity_selection","lastContentName":"ECS续费升级特惠6.5折","lastContentLink":"https://www.aliyun.com/daily-act/ecs/care"}},{"infoName":"产品入门","infoContent":{"firstContentName":"ECS选型推荐","firstContentLink":"https://help.aliyun.com/document_detail/58291.html","lastContentName":"ECS学习路径","lastContentLink":"https://help.aliyun.com/learn/learningpath/ecs.html"}},{"infoName":"热门产品","infoContent":{"firstContentName":"第六代企业级产品","firstContentLink":"https://cn.aliyun.com/acts/member-2019/the-sixth-ecs","lastContentLink":"https://www.aliyun.com/product/swas","lastContentName":"轻量应用服务器"}},{"infoName":"最佳实践","infoContent":{"firstContentLink":"https://yqh.aliyun.com/live/detail/6600","firstContentName":"新产品s6首发解密","lastContentLink":"https://yqh.aliyun.com/live/detail/6641","lastContentName":"迁云工具一键上云"}}],"contentLink":"https://www.aliyun.com/product/ecs"}]}

    {"$env":{"JSON":{}},"$page":{"env":"production"},"$context":{"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],"search_count":[{"count_phone":6,"count":6}]},"card":[{"des":"云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。","link1":"https://ecs-buy.aliyun.com/wizard#/prepay/cn-hangzhou","link":"https://www.aliyun.com/product/ecs","icon":"https://img.alicdn.com/tfs/TB1afahQpXXXXaAapXXXXXXXXXX-114-114.png","btn2":"了解价格","tip":"ECS精选产品特惠低至0.95折,立即查看 高配云服务器免费试用,立即查看","btn1":"立即开通","link2":"https://www.aliyun.com/price/product?spm=5176.8789780.1092586.1.2e8e57a8lGNDpl#/ecs/detail","title":"云服务器 ECS"}],"search":[{"txt":"云服务器精选特惠,低至0.95折","link":"https://www.aliyun.com/daily-act/ecs/activity_selection"},{"txt":"ECS新产品s6首发特惠","link":"https://www.aliyun.com/daily-act/ecs/s6_sales"},{"txt":"ECS免费试用最高12个月","link":"https://www.aliyun.com/daily-act/ecs/free"},{"txt":"ECS云服务器学习路径","link":"https://help.aliyun.com/learn/learningpath/ecs.html"},{"txt":"ECS云服务器入门","link":"https://help.aliyun.com/document_detail/25422.html"},{"txt":"ECS云服务器选型推荐","link":"https://help.aliyun.com/document_detail/58291.html"}],"countinfo":{"search":{"length_pc":0,"length":0},"card":{"length_pc":0,"length":0}},"simplifiedDisplay":"newEdition","newCard":[{"link":"https://www.aliyun.com/product/ecs","icon":"ecs","title":"云服务器ECS","des":"云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。","btn1":"产品详情页","btn2":"ECS控制台","btn3":"在线咨询","link3":"https://ai.alimebot.taobao.com/intl/index.htm?from=bg778QBnk9&_user_access_token=Nm9Vb2FMUTBNMXQydUQybXRKcXFUWU52TDhnOS9yN1hRM0JjRURxaGJyNERramxUWGNMSFRENExQUnJ1RXF5K0tHTXFzbmpZL0xWS2pPN24xSVVpeHNrM2tGTVVjQXFvYnlkN09JcklrMFhLZllCTnpLbTRGKzZyME4vd3hkQzdxbjl6SnZ3YnR6MlJTdkh2cGJTc1ZRPT0=","link1":"https://www.aliyun.com/product/ecs","link2":"https://ecs.console.aliyun.com/#/home","infoGroup":[{"infoName":"最新活动","infoContent":{"firstContentName":"云服务器低至0.95折","firstContentLink":"https://www.aliyun.com/daily-act/ecs/activity_selection","lastContentName":"ECS续费升级特惠6.5折","lastContentLink":"https://www.aliyun.com/daily-act/ecs/care"}},{"infoName":"产品入门","infoContent":{"firstContentName":"ECS选型推荐","firstContentLink":"https://help.aliyun.com/document_detail/58291.html","lastContentName":"ECS学习路径","lastContentLink":"https://help.aliyun.com/learn/learningpath/ecs.html"}},{"infoName":"热门产品","infoContent":{"firstContentName":"第六代企业级产品","firstContentLink":"https://cn.aliyun.com/acts/member-2019/the-sixth-ecs","lastContentLink":"https://www.aliyun.com/product/swas","lastContentName":"轻量应用服务器"}},{"infoName":"最佳实践","infoContent":{"firstContentLink":"https://yqh.aliyun.com/live/detail/6600","firstContentName":"新产品s6首发解密","lastContentLink":"https://yqh.aliyun.com/live/detail/6641","lastContentName":"迁云工具一键上云"}}],"contentLink":"https://www.aliyun.com/product/ecs"}]}}

    展开全文
  • python3 uwsgiconfig.py --build # 使用Python3进行编译 然后将编译出来的 uwsgi 复制到系统目录: sudo cp ./uwsgi /usr/bin/ 可以通过查看uWSGI版本来判断是否编译成功: [外链图片转存失败,源站...

    #1.安装Nginx

    sudo yum install -y nginx
    sudo systemctl start nginx.service # 开启Nginx服务
    sudo systemctl enable nginx.service # 设为开机启动
    

    开启Nginx服务后,用浏览器访问本机就可以看到Nginx的默认页面:
    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ZaFs5BM4-1576482531941)(http://ofpb4e3i2.bkt.clouddn.com/18-5-28/91876700.jpg)]


    #2.编译uWSGI

    wget http://projects.unbit.it/downloads/uwsgi-2.0.17.tar.gz
    tar zxvf uwsgi-2.0.17.tar.gz
    cd uwsgi-2.0.17
    python3 uwsgiconfig.py --build # 使用Python3进行编译
    

    然后将编译出来的 uwsgi 复制到系统目录:

    sudo cp ./uwsgi /usr/bin/
    

    可以通过查看uWSGI版本来判断是否编译成功:
    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-MDJu1cW1-1576482531942)(http://ofpb4e3i2.bkt.clouddn.com/18-5-28/41946293.jpg)]


    #3.配置Nginx

    sudo vim /etc/nginx/nginx.conf
    

    在Nginx配置文件的最后一个右大括号前添加一行:include /etc/nginx/sites-enabled/*.conf;,代表将/etc/nginx/sites-enabled目录下的所有.conf配置文件托管至Nginx。这个目录可以自由指定。
    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-LaQG5eO9-1576482531943)(http://ofpb4e3i2.bkt.clouddn.com/18-5-28/63109088.jpg)]
    在指定的这个目录下面,添加.conf配置文件。比如:

    server {
        listen       80; # 默认端口号,不用改
        server_name  test.cn; # 当用户用这个域名访问Nginx时,调用本配置文件
        location / {            
            include  uwsgi_params;
            uwsgi_pass 127.0.0.1:9090; # 将所有请求转发给本机9090端口的uWSGI程序
        }
    }
    

    #4.配置uwsgi站点
    在站点根目录(可以自由指定)建立uwsgi启动配置文件,如setting.ini:

    [uwsgi]
    pythonpath=/home/test/website # 站点根目录
    module=run                       # .py文件名
    callable=app                     # 程序入口
    socket=127.0.0.1:9090            # 端口号,与第3部分的uwsgi_pass参数要一致
    processes=1                      # 线程数为1
    py-autoreload=1                  # 当.py文件被修改时自动重载
    

    目录结构如下:

    ~/website/
      --setting.ini
      --run.py
    

    run.py的入口为app:

    from flask import Flask
    app = Flask(__name__)
    
    @app.route('/')
    def hello_world():
        return 'Hello World!'
    

    #5.其他

    uwsgi -i /home/test/website/setting.ini -d uwsgi.log # 启动uWSGI
    killall -9 uwsgi # 结束uWSGI
    
    展开全文
  • Python3搭建本地web服务器

    千次阅读 2018-08-08 11:29:29
    Python3搭建本地web服务器 终端输入: python3 -m http.server 3000 会在本地建立一个服务器。起始目录为 当时终端所在目录。 -m module-name http.server python模块- HTTP服务器 3000 端口确定,可以为其他...

    Python3搭建本地web服务器

    终端输入:

    python3 -m http.server 3000

    会在本地建立一个服务器。起始目录为 当时终端所在目录

    • -m module-name
    • http.server python模块- HTTP服务器
    • 3000 端口确定,可以为其他

    根据上面命令,浏览器输入 localhost:3000/ 即可访问


    设置其他的绑定的特定地址

    版本3.4中的新增功能

    python3 -m http.server 8000 --bind 127.0.0.1
    • -b/–bind 指定应绑定的特定地址

    设置指定目录

    版本3.7中的新增功能

    python -m http.server --directory /tmp/
    • -d/–directory 指定应为其提供文件的目录
    展开全文
  • windows / python3.8 / Tornado / NotImplementedError 问题三. 跨域访问问题1. 什么是跨域2. 为什么浏览器要限制跨域访问3. 为什么要跨域4 解决办法四. GET如何获取参数五. POST如何获取参数六. javascript执行GET...
  • 静态文件多进程版:—————————————————————————————————————————————阅读本代码需要的前期知识:1、Python网络编程2、了解HTTP协议3、多进程,多线程4、socket套接字5、...
  • python2: python -m SimpleHTTPServer 8888 python3: python -m http.server 8888 wget ip:8888/文件 转载于:https://www.cnblogs.com/xinfang520/p/10458676.html
  • 搭建Python + Apache + mod_python环境:1、说起服务器,当然少不了Apache,不用安装这么麻烦,下载个XAMPP就好了,注意里面的Apache要是2.2版本。2、下载Python2.5.x,安装,也要注意版本。3、下载mod_python-...
  • Python搭建简单的web服务器1.win+R输入cmd打开命令行2.通过cd进入到你保存 HTML 文件的目录。例如:H:\D3\d3输入 cd\ 指令进入到C盘的根目录。(CD(更改目录)。使用此命令可以更改当前目录)这里解释一下cd指令基本...
  • python搭建简易web服务器,局域网

    千次阅读 2019-10-28 19:34:18
    python自带一个WEB服务器SimpleHTTPServer,利用python搭建一个http服务器 python2命令:python-mSimpleHTTPServer8000& python3命令:python3 -m http.server 8000 & 这样就可以在浏览器中通过http:***...
  • 在本机搭建Web服务器其实也有更简单的方法,可以利用iis功能。可以自行搜索本机iis搭建Web服务器。不用写代码,Windows自带的web服务器功能。Python2提供了BaseHTTPServer模块,不过在Py3把它合并到了http.server中...
  • Python3搭建http服务器

    2020-02-09 20:27:44
    在本机搭建Web服务器其实也有更简单的方法,可以利用iis功能。可以自行搜索本机iis搭建Web服务器。不用写代码,Windows自带的web服务器功能。 Python2提供了BaseHTTPServer模块,不过在Py3把它合并到了http.server中...
  • 在本机搭建Web服务器其实也有更简单的方法,可以利用iis功能。可以自行搜索本机iis搭建Web服务器。不用写代码,Windows自带的web服务器功能。 Python2提供了BaseHTTPServer模块,不过在Py3把它合并到了http.server...
  • 于是,开始了我的搭建web服务器之旅。  首先,如果不想使用Apache、IIS,那就需要一个HTTP服务,而python自带了一个SimpleHTTPServer库,就可以帮助自己完成搭建一个HTTP服务器。当然,库的安装步骤我就不写了。 ...
  • 2. 如何搭建Python自带的静态Web服务器3. 访问搭建的静态Web服务器4. 查看浏览器和搭建的静态Web服务器的通信过程 1. 静态Web服务器是什么? 可以为发出请求的浏览器提供静态文档的程序。 平时我们浏览百度新闻数据...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 404
精华内容 161
关键字:

python3搭建web服务器

python 订阅