用 Requests 出了一些问题,求大侠指导,谢谢 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
kchum

用 Requests 出了一些问题,求大侠指导,谢谢

  •  
  •   kchum Jul 6, 2014 3319 views
    This topic created in 4314 days ago, the information mentioned may be changed or developed.
    A:登陆url B:会员中心(登陆访问) C:申请页面(需登陆访问)

    1.登陆A
    s = requests.Session()
    data = {'username': 'value1', 'password': 'value2'}
    r = s.post("http://example.com/login", data = data)

    2.请求B
    r = s.get("http://example.com/member")
    r.text
    里有username了,说明登陆成功了吧

    3.请求C
    r = s.get("http://example.com/apply")
    r.text
    里提示
    a).your session has timed-out.
    b).you don't have 'cookies' enabled on your browser.
    session都是用同一个对象去请求的,应该不是这个原因吧

    headers,抓包信息排查过了
    那么是不是基本下定论是cookies的原因?
    我看到页面有看到用js操作cookies的,是不是这个原因?
    Python里有什么简单快速的方案解决这个问题,能获取js生成到cookies?

    求大侠指点下,非常感谢!
    Supplement 1    Jul 6, 2014
    抓包和运行详情详情如下

    1.登陆A
    s = requests.Session()
    data = {'username': 'value1', 'password': 'value2'}
    r = s.post("http://example.com/login", data = data)
    ###抓包分析Set-Cookie Auth=xxxxxx , Code = xxxxxxxx ,Python运行一样

    2.请求B
    r = s.get("http://example.com/member")
    r.text
    ###r.text里有username了,说明登陆成功了吧
    ##抓包分析cookies与A的一致,Python运行也一致

    3.请求C
    r = s.get("http://example.com/apply")
    r.text
    ###抓包分析请求C Set-Cookie History=xxxxx , Code = xxxxxxxxx
    ###Python运行获取不到History和新 Code

    真纠结~~~
    5 replies    2014-07-06 11:22:38 +08:00
    sandtears
        1
    sandtears  
       Jul 6, 2014
    读一下 JS 源码照着生成一下呗,反正 js 这种东西都是公开的
    kchum
        2
    kchum  
    OP
       Jul 6, 2014
    @sandtears 重新抓包看了下各个url请求header cookie信息和Python的对比,name数是一样的。
    应该跟Js无关。

    抓包流程
    登陆A时setcookie Auth=xxxxxx
    Code = xxxxxxxx

    请求B,还是A的Cookies

    请求C,又setcookie History=xxxxx
    Code = xxxxxxxxx

    Python在C这一步获取不到C设置的cookie(也就是C页面没设置成功History,新Code)

    请问,有哪些情况会导致这种情况出现?

    谢谢~~
    ushuz
        3
    ushuz  
       Jul 6, 2014
    把headers设置成和浏览器一模一样试试,可能在apply那一步加了一些对headers的验证。
    sandtears
        4
    sandtears  
       Jul 6, 2014
    @kchum 没看明白你的意思,你请求 C 不是设置了新的 Cookie -> History 么, name 数怎么会一样
    jsonline
        5
    jsonline  
       Jul 6, 2014 via Android
    cookie过期时间多久?
    About     Help     Advertise     Blog     API     FAQ     Solana     975 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 51ms UTC 20:35 PVG 04:35 LAX 13:35 JFK 16:35
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86