黑发 2015-05-06 12:40 采纳率: 0%
浏览 4359
已结题

用python模拟新浪微博登录出现retcode=4049

是要输入验证码吗?我已经设置了再部分区域不用输入验证码了。求大神回答
模拟登陆的代码如下:

-*- coding: utf-8 -*-

import requests
import base64
import re
import urllib
import rsa
import json
import binascii
import string
from weibo import Client
import random
import time
import logging, logging.handlers
'''
code = "5f9f84b2aa3198032416963c84c2d182"
app_key = "4055744185"
app_secret = "838ec8be666e6116c4e483ed14e5fea4"
redirect_uri = "https://api.weibo.com/oauth2/default.html"
user_name = '412062385@qq.com'
pwd = 'googlesina'
'''

class SinaCrawler:
def init(self, max_page):
self.session = None
self.MAX_PAGE = max_page
token = {u'access_token': u'2.00pE39sBn1UT7E61e7174d95TdYVED', u'remind_in': u'157679999', u'uid': u'1720813027', u'expires_at': 1575304674}
self.client = Client(app_key, app_secret, redirect_uri, token)
self.f = open("data", "w")

def __del__(self):
    self.f.close()

def userlogin(self,username,password):
    session = requests.Session()
    url_prelogin = 'http://login.sina.com.cn/sso/prelogin.php?entry=weibo&callback=sinaSSOController.preloginCallBack&su=&rsakt=mod&client=ssologin.js(v1.4.18)&_=1430736851146'
    url_login = 'http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.8)'
    #get servertime,nonce, pubkey,rsakv
    resp = session.get(url_prelogin)
    print resp.content
    p = re.compile('{.*}')
    json_data  = re.search(p, resp.content).group()
    print json_data
    data       = eval(json_data)
    servertime = data['servertime']
    print 'servertime:',servertime
    nonce      = data['nonce']
    pubkey     = data['pubkey']
    rsakv      = data['rsakv']

    # calculate su
    su  = base64.b64encode(urllib.quote(username))

    #calculate sp
    rsaPublickey= int(pubkey,16)
    key = rsa.PublicKey(rsaPublickey,65537)
    message = str(servertime) +'\t' + str(nonce) + '\n' + str(password)
    sp = binascii.b2a_hex(rsa.encrypt(message,key))
    postdata = {
        'entry': 'weibo',
        'gateway': '1',
        'from': '',
        'savestate': '7',
        'userticket': '1',
        'ssosimplelogin': '1',
        'vsnf': '1',
        'vsnval': '',
        'su': su,
        'service': 'miniblog',
        'servertime': servertime,
        'nonce': nonce,
        'pwencode': 'rsa2',
        'sp': sp,
        'encoding': 'UTF-8',
        'url': 'http://weibo.com/ajaxlogin.php?framelogin=1&callback=parent.sinaSSOController.feedBackUrlCallBack',
        'returntype': 'META',
        'rsakv' : rsakv,
    }
    resp = session.post(url_login,data = postdata)
    # print resp.headers
    login_url = re.findall('replace\(\"(.*)\"\)',resp.content)
    print 'login_url,[0]',login_url,login_url[0]
    respo = session.get(login_url[0])
    print respo.content
    self.session = session

if name == '__main__':
sina_crawler = SinaCrawler(50)
sina_crawler.userlogin('lih211@sina.com', 'ta3344521')

  • 写回答

1条回答 默认 最新

  • oyljerry 2015-05-06 14:32
    关注

    起码要先查看sdk知道返回的错误码是什么意思。

    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿