H原子 发表于 2021-5-23 20:32:14

利用session对象获得cookie,访问人人网,返回状态码500

import requests

session = requests.session()

post_url = "http://rrwapi.renren.com/account/v1/loginByPassword"
data = {"user":"13086186183"
      ,"password":"0b3011edc0c95732d0c9d9cf0d7be1a61"
      ,"appKey":"bcceb522717c2c49f895b561fa913d10"
      ,"sig":"2b9659a6d0fdf44a1cae821137146d13"
      ,"sessionKey":""
      ,"callId":"1621769695934"
      
      }
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36"
         ,"Content-Type":"application/json;charset=UTF-8"
         ,"Content-Length":"194"
         ,"Accept":"application/json, text/plain, */*"
         ,"Accept-Encoding":"gzip, deflate"
         ,"Accept-Language":"zh-CN,zh;q=0.9"
         ,"Referer":"http://www.renren.com/"
         ,"Host":"rrwapi.renren.com"
         ,"Origin":"http://www.renren.com"
         ,"Connection":"keep-alive"
         }

rep = session.post(url=post_url,data=data,headers=headers)
print(rep)

即使我把所有的请求头都打包过去都没用,求鱼油解惑!!!

YunGuo 发表于 2021-5-23 22:15:24

没有人人网账号,初步分析登录请求,可以这样做,有可能后面还需要验证图形验证码才能登录成功。
# 人人网

import requests
import json
import time
import hashlib

url = 'http://rrwapi.renren.com/account/v1/loginByPassword'
headers = {
    'Content-Type': 'application/json',
    'User-Agent': 'Mozilla/5.0'
}
t = str(int(time.time() * 1000))
user = '12321321312'
password = '12345'
pwd = hashlib.md5(password.encode()).hexdigest()
data = {
    'appKey': "bcceb522717c2c49f895b561fa913d10",
    'callId': t,
    'password': pwd,
    'sessionKey': "",
    'user': user
}
r = f'appKey=bcceb522717c2c49f895b561fa913d10callId{t}password={pwd}sessionKey=user={user}'
sig = hashlib.md5(r.encode()).hexdigest()

res = requests.post(url, headers=headers, data=json.dumps(data))
print(res.json)

H原子 发表于 2021-5-23 22:46:49

YunGuo 发表于 2021-5-23 22:15
没有人人网账号,初步分析登录请求,可以这样做,有可能后面还需要验证图形验证码才能登录成功。

十分感谢,我的问题应该是出在没有把表单数据转换为json格式,
后续确实还需要图形验证码,得亏你提了个醒,写这帖子之前还不用验证码的,差点又给整懵了
页: [1]
查看完整版本: 利用session对象获得cookie,访问人人网,返回状态码500