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")

相关文章

pytorch 常用线性函数详解

Pytorch的线性函数主要封装了Blas和Lapack,其用法和接口都与之类似。 常用的线性函数如下: 函数 功能...

使用python实现http及ftp服务进行数据传输的方法

服务器之间的http数据传输 直接使用python内置的http服务: python -m SimpleHTTPServer 8000 此时,输入指令的目录就已经开启了http服务...

python一键升级所有pip package的方法

pip_ungrade_all.py代码如下: # -*- coding: utf-8 -*- import pip from subprocess import call f...

浅谈python数据类型及类型转换

Python中核心的数据类型有哪些? 变量(数字、字符串、元组、列表、字典) 什么是数据的不可变性?哪些数据类型具有不可变性 数据的不可变是指数据不可更改,比如: a = ("ab...

Python编写一个验证码图片数据标注GUI程序附源码

Python编写一个验证码图片数据标注GUI程序附源码

做验证码图片的识别,不论是使用传统的ORC技术,还是使用统计机器学习或者是使用深度学习神经网络,都少不了从网络上采集大量相关的验证码图片做数据集样本来进行训练。 采集验证码图片,可以直接...