py模块

from pymysql.connections import Connection
#创建连接
conn = Connection(host='155.138.214.114',port=3306,user='yunwei',password='123456',database='mysql') #默认不连接 defer_conntion=True

#获取游标
cursor = conn.cursor()
print('cursor object={}'.format(cursor))
res= cursor.execute('select * from mysql.user limit 4')
#执行sql
print('取第一条的结果:',cursor.fetchone())
print('取第二条的结果:',cursor.fetchone())
print('取后五条数据',cursor.fetchmany())
print('取剩余数据',cursor.fetchall())
print('获取全部结果:{}',format(cursor._rows))
#关闭连接
cursor.close()
conn.close()

#urllib3模块
from urllib.parse import urlparse
import urllib3
test_url="http://155.138.214.114:8002"
parsed = urlparse(test_url)
pool_manager = urllib3.PoolManager()
req_url = parsed.geturl()
conn = pool_manager.connection_from_url(req_url)
respon = conn.urlopen('GET',test_url)
print('请求状态码={},请求结果={}',format(respon.status,respon.data))

#import requests 模块
import requests
respon = requests.get(test_url)
print('requests请求结果:{},{}'.format(respon.status_code,respon.content,respon.text))



posted @ 2022-09-14 08:07  人生信条~~  阅读(36)  评论(0编辑  收藏  举报