使用Python登录到网站

时间:2018-08-20 11:14:20

标签: python login web

我目前正尝试通过Python在ds-exchange(https://app.ds-exchange.co.uk/#/login/signin)上登录我的帐户(不要问为什么,我只是测试了自从学习PayPon以来我现在可以做什么:P)

我已经检查了他们在Fiddler上的登录方式:

  1. 他们在https://api.ds-exchange.co.uk/v1/get/ip/上空帖

  2. 他们会发布他们从步骤1获得的device_id,app_type,平台,app_version和标识符。@ https://api.ds-exchange.co.uk/v1/device/register/

  3. 现在他们发布电子邮件,密码(在sha256中)和access_token @ https://api.ds-exchange.co.uk/v1/login/

我已经用Python简单地重写了它:

import re
import json
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning

#disable ssl warning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

payload = {}
content = requests.post('https://api.ds-exchange.co.uk/v1/get/ip/', verify=False, params=payload)

print(content.text)


payload = {'device_id': '123123123123123', 'app_type': 'admin', 'platform': 'web', 'app_version': '2.0.1', 'identifier': '127.0.0.1'}
content = requests.post('https://api.ds-exchange.co.uk/v1/device/register/', verify=False, params=payload)

print(content.text)
answer = json.loads(content.text)
print(answer['data']['access_token'])

accesstoken = answer['data']['access_token']

payload = {'email': 'dolemites@test.de', 'password': 'dolemites', 'access_token': accesstoken}
content = requests.post('https://api.ds-exchange.co.uk/v1/login/', verify=False, params=payload)

print(content.text)

这是我从python脚本获得的答案:

步骤1:{"ts":1534762909,"success":true,"error":false,"data":{"ip_address":"::1"}}

第2步:{"ts":1534762911,"success":true,"error":false,"data":{"access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl9pZHMiOiIyZTAxZmI0MDUyZTEyZjdmMzU2OTliZWVmODU3Zjk2MTY5ODBmMDA0MDMwOTFmM2M3OTk3NzdhYzRjZDM0YTEyIiwiaWF0IjoxNTM0NzYyOTExLCJleHAiOjE1MzQ4NDkzMTEsImF1ZCI6ImNyeXB0b2JhbmsuY29tIiwiaXNzIjoiY3J5cHRvYmFuay5jb20ifQ.aYAcdRmYdRPxYtylh17gYJKjXYKiRhWlWRg-JnmFYBw"}}

第3步:{"ts":1534762912,"success":false,"error":true,"error_msg":"Access Denied. Token not found","logout":true}

问题在于,在步骤3中,我在Fiddler中获得了完全不同的答案,在此位置,我得到了这样的答案:“ error_msg”:“ dolemites@test.de未找到”

我做错了什么? :(

1 个答案:

答案 0 :(得分:0)

尝试使用库,该库用于进行单元测试。