【问题标题】:Send POST requests with values from a list使用列表中的值发送 POST 请求
【发布时间】:2017-11-10 03:17:57
【问题描述】:

我正在尝试向网站发送 http POST 请求,其中“值”键的数据是从 .txt 列表的行中提取的。

我尝试使用数组,但网站不接受多个值。相反,我需要为文件中的每个值发送一个新请求,但我不知道该怎么做。

import requests

headers = {
    'Referer': 'http://127.0.0.1:2372/overrides?sid=69',
    'Content-Type': 'application/x-www-form-urlencoded',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/604.3.5 (KHTML, like Gecko) Version/11.0.1 Safari/604.3.5',
    'Origin': 'http://127.0.0.1:2372',
    'DNT': '1',
}

data = [
  ('sid', '69'),
  ('aid', 'addEntry'),
  ('type', '0'),
  ('value', 'test3'),
]

requests.post('http://127.0.0.1:2372/k9ajax', headers=headers, data=data)


如果这是一个愚蠢的问题,我深表歉意,如果这是错误的论坛,我将删除该帖子。

【问题讨论】:

    标签: python post http-post python-requests


    【解决方案1】:

    请学习查看帮助

    >>> import requests
    >>> print(help(requests.post))
    ### some text
    :param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`.
    ### some text
    

    数据应该是一个字典

    data = {
    'sid': '7882493',
    'aid':'addEntry',
    'type': '0',
    'value':'test3'}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-24
      • 2013-10-06
      • 2015-02-28
      • 2017-02-13
      • 2021-11-30
      • 2017-05-03
      • 2017-10-30
      • 1970-01-01
      相关资源
      最近更新 更多