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的值
网友评论