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
lixuda
V2EX  ›  Python

requests post 问题

  •  
  •   lixuda · 2018-11-15 16:08:31 +08:00 · 2920 次点击
    这是一个创建于 1960 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在网站抓包时候发送 post 内容是这样 {"index":"aaa","ignore_unavailable":true,"timeout":0,"preference":1542268295267} {"aggs":"bbb"}

    多个字典

    对 post 不是很了解

    我用 requests 模拟 post 时候如何操作?

    第 1 条附言  ·  2018-11-16 09:58:11 +08:00
    感谢大家,已解决,用\n 拼接即可
    11 条回复    2018-11-16 09:13:39 +08:00
    himan85
        1
    himan85  
       2018-11-15 16:12:57 +08:00 via iPhone
    post 不支持多字典啊
    lixuda
        2
    lixuda  
    OP
       2018-11-15 16:13:25 +08:00
    @himan85 我也不懂,抓包出来就是显示这个
    kkkkkrua
        3
    kkkkkrua  
       2018-11-15 16:14:42 +08:00
    啥网站?同 1#,不支持
    lixuda
        4
    lixuda  
    OP
       2018-11-15 16:20:44 +08:00
    @himan85
    Accept: application/json, text/plain, */*
    content-type: application/x-ndjson

    json 方式吗?
    lixuda
        5
    lixuda  
    OP
       2018-11-15 16:21:30 +08:00
    @kkkkkrua
    Accept: application/json, text/plain, */*
    content-type: application/x-ndjson
    这个有关系吗?
    cece0417
        6
    cece0417  
       2018-11-15 16:24:09 +08:00
    1、拿到接口的 url 地址
    2、查看接口是用什么方式发送( get、post 或者其他的)
    3、添加请求头,请求体( header、cookies、data 之类的)
    4、发送查看返回结果,校验返回结果是否正确
    header 中有 application/json,post data 的时候要将字典转为 json 格式,可以用 json.dumps(data)转换一下
    lixuda
        7
    lixuda  
    OP
       2018-11-15 16:38:21 +08:00
    @cece0417
    Accept: application/json, text/plain, */*
    content-type: application/x-ndjson

    但是 2 个字典,我不是很懂,如何 json.dumps(data)
    monsterxx03
        8
    monsterxx03  
       2018-11-15 16:47:28 +08:00
    把两个 dict 分别 dumps, 然后用 \n 拼起来就行了, ndjson 就是 Newline delimited JSON
    himan85
        9
    himan85  
       2018-11-15 23:04:36 +08:00 via iPhone
    你用 fiddler 抓包看看 webforms 是什么结构的就很清楚了
    lixuda
        10
    lixuda  
    OP
       2018-11-16 09:13:35 +08:00
    @himan85 是用 fiddler 抓包的
    lieh222
        11
    lieh222  
       2018-11-16 09:13:39 +08:00
    jsondumps,转为字符串,然后这里怎么拼的就怎么拼,以 data 的方式发就行了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3309 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 00:04 · PVG 08:04 · LAX 17:04 · JFK 20:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.