import requests
from urllib.request import urlretrieve
login_yunduan_path = '/oauth2/oauth/token'
def login(username,password,IP,PORT):
# r = requests.get('')
# 获取验证码
IMAGE_URL = "http://47.104.63.70:5728/oauth2/captcha.jpg"
# 使用urlretrieve来下载图片
# IMAGE_URL = "http://47.104.63.70:5728/oauth2/captcha.jpg"
# urlretrieve(IMAGE_URL,'D:\\yunduan_pyzdh\\yzm\\00.jpg')
# 使用requests直接get
import requests
r = requests.get(IMAGE_URL)
cookies = r.cookies.items()
# print(cookies)
cookie = ''
for name, value in cookies:
cookie += '{0}={1};'.format(name, value)
# print(cookie)
with open('D:\\yunduan_pyzdh\\yzm\\02.jpg', 'wb') as f: # 将验证码保存在我本地路径
f.write(r.content)
# 需要调用验证码识别接口
yzmsb_url = 'http://api.ttshitu.com/create.json'
body = {
'username': 'zenghz',
'password': 'zhz134191',
'typeid': '3',
'angle': '',
'typename': '',
# 'image':'D:\\yunduan_pyzdh\\yzm\\02.jpg'
# "image":("02.jpg",open('D:\\yunduan_pyzdh\\yzm\\02.jpg','rb'),"/image/jpg")
}
file = {'image': ('02.jpg', open('D:\\yunduan_pyzdh\\yzm\\02.jpg', 'rb'), 'image/jpg')}
result = requests.post(yzmsb_url, data=body, files=file)
yzm_jg = result.json()['data']['result']
print(yzm_jg)
# 验证码识别成功以后,需要登录新云端
body1 = {
"grant_type": "password",
"client_id": "webApp",
"client_secret": "webApp",
"username": username,
"password": password,
"captcha": yzm_jg,
}
header1 = {
"Accept": "application/json, text/plain, */*",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
"Access-Control-Allow-Origin": "*",
"Connection": "keep-alive",
"Content-Length": "125",
"Content-Type": "application/x-www-form-urlencoded",
"Cookie": cookie,
"Host": "47.104.63.70:5728",
"Origin": "http://47.104.63.70:1111",
"Referer": "http://47.104.63.70:1111/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36"
}
hh = requests.post(url="http://" +IP+":" + PORT+login_yunduan_path, data=body1, headers=header1)
access_token = hh.json()['access_token'] #从返回值的集合中提取access_token的vaule
# 还需要提取access_token
# print(access_token)
return access_token
# access_token = login(username,password,IP,PORT) #拿到access_token的值
requests类库接口请求示例(云端的登录接口)
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- java可以通过Apache HttpClient请求接口数据Apache HttpClient maven ja...
- Requests 简介 Requests 是一个优雅而简单的 Python HTTP 库,其实 Python 内置...
- 一、requests 1.1、简介 Requests 是用 Python 语言编写, 基于 urllib,采用 A...
- 今天青石的票圈出镜率最高的,莫过于张艺谋的新片终于定档了。 一张满溢着水墨风的海报一次次的出现在票圈里,也就是老谋...