python client使用http post 到server端的代码

yipeiwu_com6年前Python基础
复制代码 代码如下:

import urllib, httplib 
import utils 
import json
       class User: 

        def __init__(self): 
            print 'a' 

        def login(self, imsi, ua): 
            print "==============user start login==================" 
            input = { 
                "method"       : "user.login", 
                "userName"     : "", 
                "userPass"     : "", 
            } 

            input["sig"] = utils.getSignature(input) 
            params = urllib.urlencode(input) 
            headers = { 
                "user-agent"  : ua, 
                "Appstore-clientType" : "android", 
                "Appstore-IMEI" : "123456789000000", 
                "Appstore-IMSI" : imsi 
            } 

            try: 
                connection = httplib.HTTPConnection(utils.API_HOST) 
                connection.request("POST", "/api", params, headers) 
                response = connection.getresponse().read() 
                #print "=========" + response 
                connection.close() 
            except Exception, e : 
                print "========" + str(e)     

            if "errorcode" in response or response is None: 
                return 

            results = json.loads(response)     

            return results["results"].encode("utf-8")

相关文章

Python批量修改文件后缀的方法

Python批量修改文件后缀的方法

近期下载了很多各种教程, 但是不幸的是后缀名都是 ".mp4", 而本人喜欢 ".rmvb" 后缀,由于有轻微洁癖, 受不了后面的 ".mp4" 缀, 但是手动修改又太过繁琐, 所以用近...

python中abs&map&reduce简介

abs函数 可以把函数本身赋值给变量 >>> f = abs 变量可以指向函数 >>> f = abs >>> f(-10) 10...

python 弹窗提示警告框MessageBox的实例

需要安装pywin32模块,pip install pywin32 ##pip install pywin32 import win32api,win32con ##提醒OK...

python groupby 函数 as_index详解

在官方网站中对as_index有以下介绍: as_index : boolean, default True For aggregated output, return object w...

Python求正态分布曲线下面积实例

Python求正态分布曲线下面积实例

正态分布应用最广泛的连续概率分布,其特征是“钟”形曲线。这种分布的概率密度函数为: 其中,μ为均值,σ为标准差。 求正态分布曲线下面积有3σ原则: 正态曲线下,横轴区间(μ-σ,μ+...