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

yipeiwu_com5年前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完成毫秒级抢淘宝大单功能

引言 年中购物618大狂欢开始了,各大电商又开始了大力度的折扣促销,我们的小胖又给大家谋了一波福利,淘宝APP直接搜索:小胖发福利,每天领取三次粉丝专属现金大红包。 有了现金大红包,如...

numpy:找到指定元素的索引示例

目的:在numpy数组中知道指定元素的索引 函数: np.argwhere >>>x >>>array([[0, 1, 2], [3, 4,...

python特性语法之遍历、公共方法、引用

一、遍历 通过for。。。in。。。的语法结构,我们可以遍历字符串、列表、元组、字典等数据结构。 1、字符串遍历 a_str = "hello world" for char in...

python之Flask实现简单登录功能的示例代码

python之Flask实现简单登录功能的示例代码

网站少不了要和数据库打交道,归根到底都是一些增删改查操作,这里做一个简单的用户登录功能来学习一下Flask如何操作MySQL。 用到的一些知识点:Flask-SQLAlchemy、Fla...

Python数据结构与算法之完全树与最小堆实例

本文实例讲述了Python数据结构与算法之完全树与最小堆。分享给大家供大家参考,具体如下: # 完全树 最小堆 class CompleteTree(list): def sif...