Home >Backend Development >Python Tutorial >Python POST login example code
No explanation, just give the code:
1 #!/usr/bin/env python 2 # -*- encoding: utf-8 -*- 3 4 """ 5 @version: v1.0 6 @author: elijahxb 7 @OS: linux 8 @contact: elijahxb@163.com 9 @site: 10 @software: PyCharm Community Edition 11 @file: zhangye.py 12 @time: 17-7-2 下午12:16 13 """14 15 '''16 本次登录测试:17 USERNAME:test001_00118 PASSWORD:test00119 URL: 20 TYPE: POST21 HOST: www.zhangye.ccoo.cn22 POSTURL: 23 POSTDATA:username=test001_001&password=test00124 ''' 25 import httplib26 import urllib27 28 HOST = '182.92.232.234' 29 SOURCEURL = ""30 POSTURL = '' 31 PORT = 8032 STRICT = False # 默认False,表示无法解析服务器返回的状态行时,是否抛出BadStatusLine异常 33 TIMEOUT = 534 HEADERS = { 35 'Content-type': 'application/x-www-form-urlencoded', 36 "Accept": "*/*"37 }38 TestDATA = {39 'username': 'test001_001', 40 'password': 'test001'41 }42 TestDATA = urllib.urlencode(TestDATA) try:45 # Conn = httplib.HTTPConnection(HOST, PORT, STRICT, TIMEOUT, SOURCEURL)46 HttpClient = httplib.HTTPConnection(HOST)47 HttpClient.request('POST', POSTURL, TestDATA, HEADERS)48 49 response = HttpClient.getresponse()50 print response.status51 print response.reason52 print response.read()53 print response.getheaders()54 except Exception, e:55 print e56 finally:57 if HttpClient:58 HttpClient.close()
The above is the detailed content of Python POST login example code. For more information, please follow other related articles on the PHP Chinese website!