I want to send a request to a site with curl or python's requests module but I'm getting 503
我想用cURL或python的请求模块向站点发送请求,但我收到了503
How to solve it in curl or python requests?
如何在cURL或PYTHON请求中解决?
from requests import post
json = {"somedata": "somevalue"}
cookies = {"somecookie": "somevalue"}
headers = {"someheader": "somevalue"}
print(post("https://www.example.com/", cookies=cookies, data=json, headers=headers).text)
Output:
产出:
<html>
<head><title>503 Service Temporarily Unavailable</title></head>
<body>
<center><h1>503 Service Temporarily Unavailable</h1></center>
<hr><center>Site</center>
</body>
</html>
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
It's same for curl too.
对于Curl来说也是如此。
I just want to send request normally, example:
我只想正常发送请求,例如:
from requests import post
json = {"somedata": "somevalue"}
cookies = {"somecookie": "somevalue"}
headers = {"someheader": "somevalue"}
print(post("https://www.example.com/", cookies=cookies, data=json, headers=headers).text)
Output:
产出:
{
"success":true
}
更多回答
Btw if it's possible, i can use another tool too
顺便说一句,如果可能的话,我也可以使用其他工具
The answer really depends on the particular site. It's up to the site to define what the exact request should look like in order to provide you with the data you want. Either specify what service you communicate with or ask the site provider for documentation.
答案实际上取决于具体的网站。这取决于网站定义确切的请求应该是什么样子,以便为您提供您想要的数据。指定与您通信的服务或向站点提供商索取文档。
优秀答案推荐
You might want to examine the source code of the Nginx web server! (Just see that link.) This source file literally contains this string message using the name ngx_http_msie_padding
and it has that line six times. And this code is old already.
Further onwards in the same code, Nginx is checking if it returns an error page and if it isn't long enough, it wil pad the response with this additional string. Well, that is when you're using Internet Explorer or Chrome (Chromium) as a browser.
Apparently, these browsers complain when an user-friendly error page isn't big enough to contain some user-friendly message so the padding is added to fool the browser into thinking it is still user-friendly.
Now, because Nginx generates this weird padding, this also means that Nginx is noticing a server error. I assume that Nginx is used with port forwarding to send the request to some other running process and that other process might be down or unresponsive. So the 503 error is generated and with it you get the extra padding.
This means that it's still a server issue, or something like a proxy between you and the server. You cannot solve this in the client. (Unless the site crashes because you've sent invalid data!)
您可能想要检查Nginx Web服务器的源代码!(只需查看该链接。)这个源文件包含名为ngx_http_msie_pAddding的字符串消息,并且该行重复了六次。而且这个代码已经很旧了。在相同的代码中,Nginx正在检查它是否返回错误页,如果不够长,它将用这个额外的字符串填充响应。好吧,那就是当你使用Internet Explorer或Chrome(Chromium)作为浏览器时。显然,当用户友好的错误页面不够大,无法包含一些用户友好的消息时,这些浏览器会抱怨,所以添加了填充,以欺骗浏览器认为它仍然是用户友好的。现在,因为nginx生成了这个奇怪的填充,这也意味着nginx注意到了一个服务器错误。我假设nginx与端口转发一起使用,以将请求发送到其他正在运行的进程,并且其他进程可能关闭或没有响应。因此,生成了503错误,并随之获得额外的填充。这意味着这仍然是一个服务器问题,或者说是您和服务器之间的代理。您无法在客户端解决此问题。(除非站点因您发送的无效数据而崩溃!)
"a padding to disable MSIE and Chrome friendly error page" error can occur due to several reasons, including a temporary server issue, bad browser cache, DNS problems, and even issues with your servers.
“A PADDING TO DISABLE MSIE and Chrome Friendly Error Pages”错误可能是由几个原因引起的,包括临时服务器问题、错误的浏览器缓存、DNS问题,甚至您的服务器问题。
The 503 code usually means that a server is temporarily unable to handle the request, so maybe it's not you'r fault.
503代码通常意味着服务器暂时无法处理请求,因此这可能不是您的错。
As the other responses mentioned, the 503
HTTP status code means a "server side error" occured, so the issue is on server side. You have to analyze the server logs to get more details about the exact cause. Here more details on the different HTTP status code values:
正如前面提到的其他响应,503HTTP状态代码表示发生了“服务器端错误”,所以问题出在服务器端。您必须分析服务器日志以获取有关确切原因的更多详细信息。以下是有关不同的HTTP状态代码值的更多详细信息:
更多回答
it's not a server issue, it's occurring just when send request with without a browser
这不是服务器问题,它只是在没有浏览器情况下发送请求时发生
Any HTTP error code that starts with a 5xx is a server-side issue. Either your server is misconfigured, or it's not gracefully handling a bad request. If it works in a browser, but not via cURL then it's probably the a required header is missing, or maybe that some kind of security mechanism is kicking in. Either way, this question needs more info to come to a useful answer.
任何以5xx开头的HTTP错误代码都是服务器端问题。可能是您的服务器配置错误,或者它没有正确地处理错误的请求。如果它在浏览器中工作,但不是通过cURL,那么它可能是缺少a Required标头,或者可能是某种安全机制正在发挥作用。无论哪种方式,这个问题都需要更多信息才能得出有用的答案。
我是一名优秀的程序员,十分优秀!