Python3请求 - 使用表单数据发布请求 [英] Python3 request - Post request with Form Data

查看:214
本文介绍了Python3请求 - 使用表单数据发布请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图发送带有表单数据的POST请求到某种形式。我正在使用请求包。



$ p $ #!/ bin / python3.6
导入请求

FFF_search ='https ://www.fff.fr/la-vie-des-clubs/resultats'
data = {'address':75000}
session = requests.session()
r = session。 post(FFF_search,data = data,headers = {'User-Agent':'test'})
print(r.text)

这给了我找不到结果的结果页面。

也许我的问题更多的是关于我发送的数据。
这是POST请求,因为它必须在网站上完成(Chrome开发工具)。



解决方案

您应该考虑几个问题:


  • 您的标题字典无效。没有称为测试的用户 - Agnet。您应该只使用有效标题标题。尝试发送您在网络标签中看到的所有标题。

  • 您的数据明显错误。您应该将描述的表单数据广告发送给字典,并像 data> data 一样传递它(但是您使用的是错误的数据)。也许你现在传递的数据是 params




尝试发送像浏览器发送的确切请求(使用相同的参数和标题),并查看您收到的结果,同时关注上述问题。

I'm trying to send a POST Request with form data to some form. I'm using requests package.

#!/bin/python3.6
import requests

FFF_search = 'https://www.fff.fr/la-vie-des-clubs/resultats'
data = {'address':75000}
session = requests.session()
r = session.post(FFF_search, data=data, headers={'User-Agent':'test'})
print(r.text)

This gives me the result page where no result is found.

Maybe my problem is more about the data I'm sending. Here's the POST request as it must be done on the website (Chrome dev tools).

解决方案

You should consider several issues:

  • Your's headers dict is not valid. There is no 'User-Agnet' that called test. You should use only valid headers headers. Try to send all the headers you see in the network tab.

  • Your's data us clearly wrong. You should send the described Form Data ad a dictionary and pass it with data=data, as you do (but you do it with a wrong data). Maybe the data you are passing now is the params?

Try to send the exact request like your's browser sending (with the same params and headers), and see the results you are receiving, with paying attention to the issues above.

这篇关于Python3请求 - 使用表单数据发布请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆