V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
joson1205
V2EX  ›  Python

Requests 需要怎样才能添加 COOKIES,,求解?

  •  
  •   joson1205 · 2019-08-26 10:28:26 +08:00 · 2455 次点击
    这是一个创建于 1697 天前的主题,其中的信息可能已经有所发展或是发生改变。
    cookies = {"uid": self.uid,"Hm_lvt_": str(int(time.time())),"Hm_lpvt_": str(int(time.time()))}
    payload = {"page": i, "pagesize": 100}
    res = requests.post(indexUrl + "/cert-wall", headers=headers, data=payload, cookies=cookies)
    if res.status_code == 200:
        print(res.cookies)
    

    上面这段代码,在 win 系统下测试是没问题的,但是部署到 Linux 下就报错了,打印出来的 COOKIES 值居然是空的,为什么添加不成功??搞不明白,,, 尝试过更换 requests 版本,也是一样的..

    2 条回复    2019-08-26 10:35:39 +08:00
    u823tg
        1
    u823tg  
       2019-08-26 10:33:51 +08:00
    这才是你设置的头 r.request.headers 你那个打印的是返回
    locoz
        2
    locoz  
       2019-08-26 10:35:39 +08:00
    Response.cookies 是服务器返回的 Cookie,Response.request.headers 里的 Cookie 才是你请求的时候发出去的,看文档好吧?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1221 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 23:26 · PVG 07:26 · LAX 16:26 · JFK 19:26
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.