Python 使用“请求”模块过帐数据时出现400错误请求错误

Python 使用“请求”模块过帐数据时出现400错误请求错误,python,python-requests,Python,Python Requests,标题说明了一切,奇怪的是,没有数据的GET请求和POST请求不会导致此错误发生。我想我发布的数据可能有问题,但不太确定。顺便说一句,我正在使用cfscrap模块Re:绕过Cloudflare DDoS保护加载页面。不管怎样,代码如下: payload = { "username" : "testusername", "password" : "testpassword", "code" : "1111", "submit" : "Login" } scraper = cfscrape.creat

标题说明了一切,奇怪的是,没有数据的GET请求和POST请求不会导致此错误发生。我想我发布的数据可能有问题,但不太确定。顺便说一句,我正在使用cfscrap模块Re:绕过Cloudflare DDoS保护加载页面。不管怎样,代码如下:

payload = { "username" : "testusername", "password" : "testpassword", "code" : "1111", "submit" : "Login" }
scraper = cfscrape.create_scraper()
res = scraper.post("http://www.umggaming.com/user/login", data=payload)
print res.content
我在发布数据时得到的响应是

<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>cloudflare-nginx</center>
</body>

编辑:我可以用上面的代码绕过Cloudflare,但在发送POST请求时没有得到预期的响应。如果提交的用户名/密码/代码对无效,则页面应以“对不起,您的密码或代码不正确”作为响应-我没有收到该响应。关于为什么会发生这种情况,有什么想法吗?

我使用Python urllib测试了您的问题。我发现:

如果你没有这个网站的cookie,它会给你一个503代码和cookie-cfduid

在503页面中,它发送一个请求/cdn cgi/l/chk_jschl?xxxxx以获得另一个cookie cf_许可

然后,您可以使用这两个cookie和标题中的referer来发送post表单


这是一个老问题,但由于它是谷歌的顶级搜索结果,我将提供修复它的方法,同时尝试获得一个非常相似的结果

其实很简单:如果您尚未获得授权,Cloudflare似乎不会接受post请求。这意味着您首先必须对该域发出一个简单的GET请求,让cfscrape绕过它,然后您就可以发布任何您想要的内容

上述代码的简单修复方法是:

payload = { "username" : "testusername", "password" : "testpassword", "code" : "1111", "submit" : "Login" }
url = "http://www.umggaming.com/user/login"

scraper = cfscrape.create_scraper()
scraper.get(url) # Make a simple GET request to bypass CloudFlare and get the authorisation cookies first
res = scraper.post("http://www.umggaming.com/user/login", data=payload)

print res.content

你试过了吗http://www.umggaming.com/user/login/ 最后是正斜杠?@Danoram刚刚试过,但仍然得到同样的错误。我也尝试过删除www,但没有成功。我认为该表单不允许来自不同来源的帖子。我试着从Chrome上取下这篇未经处理的文章,然后把它扔到POSTman上,POSTman的回复是一个服务不可用的503错误。@c1phr-Hmm,有人对如何解决这个问题有什么建议吗?可能是因为mechanize不包含javascript支持,所以使用cfscrape获取cookie,这就是Cloudflare DDoS保护检查的内容,然后使用mechanize模拟浏览器提交表单?绕过Cloudflare不是问题,cfscrape已经做到了这一点,它能够有效地通过GET请求检索html。问题是在向/user发布数据时,我一直收到400个错误请求/login@Impelled我把cookie放在标题中,得到了一个200码的帖子。不幸的是,仍然没有看到任何成功。。。尝试使用urllib。用我的代码更新了帖子。
payload = { "username" : "testusername", "password" : "testpassword", "code" : "1111", "submit" : "Login" }
url = "http://www.umggaming.com/user/login"

scraper = cfscrape.create_scraper()
scraper.get(url) # Make a simple GET request to bypass CloudFlare and get the authorisation cookies first
res = scraper.post("http://www.umggaming.com/user/login", data=payload)

print res.content