【问题标题】:I cant send a form/data with python我无法使用 python 发送表单/数据
【发布时间】:2021-11-18 17:34:51
【问题描述】:

我正在尝试通过 POST 发送电子邮件和密码,但我在下面的代码中执行此操作的方式不起作用。 我怎样才能正确地做到这一点?

import requests
inf = '{"user_email": "celes.....bosa@gmail.com", "user_password": "xxxxxxxxx"}'
z = requests.post('https://www.iped.com.br/api/user/login', data=inf)
print(z)
print(z.json())

【问题讨论】:

  • 试试inf = {"user_email": "celes.....bosa@gmail.com", "user_password": "xxxxxxxxx"} requests.post('https://www.iped.com.br/api/user/login', json=inf)

标签: python-3.x python-requests


【解决方案1】:

您需要将inf 设为dict 才能使用data= 参数发送。

查看requests.post的帮助:

post(url, data=None, json=None, **kwargs)
Sends a POST request.

:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
    object to send in the body of the :class:`Request`.
:param json: (optional) json data to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:return: :class:`Response <Response>` object
:rtype: requests.Response

请务必检查:How to POST JSON data with Python Requests?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-02
    • 1970-01-01
    • 2018-01-04
    • 1970-01-01
    • 2019-04-30
    • 1970-01-01
    • 2023-01-08
    • 1970-01-01
    相关资源
    最近更新 更多