zoukankan      html  css  js  c++  java
  • python 貌似没法自动识别编码

     [root@yyjk flask]# cat mojo.py
    # !/usr/bin/env python
    # -*- coding: utf-8 -*-
    from flask import Flask,request
    from lib.Mojo.Client import *
    import chardet
    
    app = Flask(__name__)
    ##装饰器作用,是做一个URL与视图函数的映射
    @app.route('/api/SMSinfo/')
    def sms():
       message = request.args.get('message')
       print message
       print '----------------'
       print type(message)
       print len(message)
       print '----------------'
       phone=request.args.get('phone')
       #print phone
       #a=New()
       #a.LoadDB(message,phone);
       #a.Sms(message,phone)
       return 99
    #print phone
    # return {"param":request.args.get('abc')}
    
    if __name__ == '__main__':
       app.run(host='0.0.0.0',port=6001,debug=True)
       
       
     
     浏览器发送请求:http://10.5.100.232:6001/api/SMSinfo/?message=%E6%B0%B4%E6%9E%9C&phone=18072722237
     
     [root@yyjk flask]# vim mojo.py
    [root@yyjk flask]# python mojo.py
     * Running on http://0.0.0.0:6001/ (Press CTRL+C to quit)
     * Restarting with stat
     * Debugger is active!
     * Debugger PIN: 677-847-682
    水果
    ----------------
    <type 'unicode'>
    2
    ----------------
    
    
    
    shell utf8 终端测试:
    [root@yyjk pfwx-master]# echo $LANG
    zh_CN.UTF-8
    [root@yyjk pfwx-master]# curl 'http://10.5.100.232:6001/api/SMSinfo/?message=蔬菜&phone=18072722237'
    
    
    蔬菜
    ----------------
    <type 'unicode'>
    2
    ----------------
    
    
    
    shell gbk 终端测试:
    
    
    [root@yyjk ~]# echo $LANG
    zh_CN
    [root@yyjk ~]# curl 'http://10.5.100.232:6001/api/SMSinfo/?message=牛奶&phone=18072722237'
    
    ???
    ----------------
    <type 'unicode'>
    3
    ----------------
    10.5.100.232 - - [22/Dec/2017 09:12:39] "GET /api/SMSinfo/?message=?ō&phone=18072722237 HTTP/1.1" 500 -
    
    
    python 貌似没有好的法子,区分编码
    

  • 相关阅读:
    自编游戏
    宣言
    Leetcode: 12. Integer to Roman
    Leetcode: 11. Container With Most Water
    Leetcode: 10. Regular Expression Matching
    网络编程:listen函数
    网络编程:connect函数
    Leetcode: 9. Palindrome Number
    Leetcode: 8. String to Integer (atoi)
    Leetcode: 7. Reverse Integer
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349386.html
Copyright © 2011-2022 走看看