推荐学习书目
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
krisbai
V2EX  ›  Python

请教下 Python 脚本中 json 格式如何引用变量

  •  
  •   krisbai · Jul 1, 2020 · 2536 views
    This topic created in 2143 days ago, the information mentioned may be changed or developed.
    ---部分代码

    a = xx

    params = {
    'page_title': 'wiki_test',
    'page_content': 'a',
    'cat_name': 'G'
    }

    resp = requests.post(url, data=params, headers=headers)
    ---

    其中 page_content 提交后还是 a,并没有引用变量值。
    css3
        1
    css3  
       Jul 1, 2020
    你都 'a'了,当的字符串啊。把 a 上边的引号去掉
    krisbai
        2
    krisbai  
    OP
       Jul 1, 2020
    @css3 谢谢老哥,我以为没有''json 就无法识别呢。。。
    renmu123
        3
    renmu123  
       Jul 1, 2020 via Android   ❤️ 1
    这是 dict 可不是 json,只是两者有点像
    ibegyourpardon
        4
    ibegyourpardon  
       Jul 1, 2020   ❤️ 1
    楼主好可爱。。。
    Molita
        5
    Molita  
       Jul 1, 2020   ❤️ 1
    23333333
    iyaozhen
        6
    iyaozhen  
       Jul 1, 2020   ❤️ 1
    楼主这个真是一言难尽

    0. 变量和字符串这也就不说了
    1. params 不是 json,是 Python 内置 dict
    2. post data=params 也是 post 的 form-data 格式,要 post json 应该写 json=params
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5494 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 552ms · UTC 07:51 · PVG 15:51 · LAX 00:51 · JFK 03:51
    ♥ Do have faith in what you're doing.