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 Numpy数组扩展repeat和tile使用实例解析

这篇文章主要介绍了Python Numpy数组扩展repeat和tile使用实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 n...

pyttsx3实现中文文字转语音的方法

如下所示: import pyttsx3 import io import sys sys.stdout = io.TextIOWrapper(sys.stdout.buffer,...

python通过百度地图API获取某地址的经纬度详解

python通过百度地图API获取某地址的经纬度详解

前言 这几天比较空闲,就接触了下百度地图的API(开发者中心链接地址:http://developer.baidu.com/),发现调用还是挺方便的,本文将给大家详细的介绍关于pytho...

基于python神经卷积网络的人脸识别

基于python神经卷积网络的人脸识别

本文实例为大家分享了基于神经卷积网络的人脸识别,供大家参考,具体内容如下 1.人脸识别整体设计方案 客_服交互流程图: 2.服务端代码展示 sk = socket.socke...

python中__call__内置函数用法实例

本文实例讲述了python中__call__内置函数的用法。分享给大家供大家参考。具体分析如下: 对象通过提供__call__(slef, [,*args [,**kwargs]])方法...