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

requests.Request()方法怎么传一个 PHP 可以接收的数组对象呢?

  •  
  •   Abigale233 · 2017-03-17 18:26:31 +08:00 · 4100 次点击
    这是一个创建于 2600 天前的主题,其中的信息可能已经有所发展或是发生改变。
    部分代码:

    post_data = {"gameId": 1,
    "activityType": 2,
    "title": "炉石常规 17 日 14:30",
    "activity_rule_id": 3,
    "activity_people": 1,
    "model": "common",
    #timerule 是出问题的地方
    "timerule": "['2017-03-18 15:11', '2017-03-18 15:21', '2017-03-18 15:31', '2017-03-18 15:41']",
    "password": 111111,
    "remark": "1111",
    "frozen": "100",
    "common_rewardrule": "{'1':'60','2':'30','3':'10'}"}

    request = requests.post(create_match_url, post_data, headers=headers)


    post_data 中的 timerule , php 后台要求是一个 array ,请问怎么转换呢?
    我尝试过写成这样:
    "timerule": ['2017-03-18 15:11', '2017-03-18 15:21', '2017-03-18 15:31', '2017-03-18 15:41']
    但是仍然不行。
    requests.Request 方法传递 json 是不是只能转换成 str 呢?
    3 条回复    2018-06-03 19:00:06 +08:00
    torbrowserbridge
        1
    torbrowserbridge  
       2017-03-17 18:33:40 +08:00 via iPhone   ❤️ 1
    这样其实是可以的,但是 php 需要先做 parse. 默认是 application/x-www-form-urlencoded 数据
    WWd0g
        2
    WWd0g  
       2018-06-03 18:59:56 +08:00
    你写成这样
    ```python
    "timerule[]": ['2017-03-18 15:11', '2017-03-18 15:21', '2017-03-18 15:31', '2017-03-18 15:41']
    ```
    WWd0g
        3
    WWd0g  
       2018-06-03 19:00:06 +08:00
    ```
    "timerule[]": ['2017-03-18 15:11', '2017-03-18 15:21', '2017-03-18 15:31', '2017-03-18 15:41']
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5052 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 100ms · UTC 01:14 · PVG 09:14 · LAX 18:14 · JFK 21:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.