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

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

  •  
  •   krisbai · 2020-07-01 12:01:35 +08:00 · 1967 次点击
    这是一个创建于 1367 天前的主题,其中的信息可能已经有所发展或是发生改变。
    ---部分代码

    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  
       2020-07-01 12:03:44 +08:00
    你都 'a'了,当的字符串啊。把 a 上边的引号去掉
    krisbai
        2
    krisbai  
    OP
       2020-07-01 12:06:46 +08:00
    @css3 谢谢老哥,我以为没有''json 就无法识别呢。。。
    renmu123
        3
    renmu123  
       2020-07-01 12:31:02 +08:00 via Android   ❤️ 1
    这是 dict 可不是 json,只是两者有点像
    ibegyourpardon
        4
    ibegyourpardon  
       2020-07-01 12:50:05 +08:00   ❤️ 1
    楼主好可爱。。。
    Molita
        5
    Molita  
       2020-07-01 12:51:20 +08:00   ❤️ 1
    23333333
    iyaozhen
        6
    iyaozhen  
       2020-07-01 13:04:09 +08:00   ❤️ 1
    楼主这个真是一言难尽

    0. 变量和字符串这也就不说了
    1. params 不是 json,是 Python 内置 dict
    2. post data=params 也是 post 的 form-data 格式,要 post json 应该写 json=params
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2809 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 12:56 · PVG 20:56 · LAX 05:56 · JFK 08:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.