python - 响应 503 python 请求

标签 python python-3.x python-requests http-status-code-503

嗨,我正在尝试向 https://www.playerup.com/ 发送请求带有打击代码:

import requests
header = {"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36"}
r = requests.get("https://www.playerup.com/",headers=header)
print(r.status_code)

但它给了我一个[503]类型错误 我尝试超时 5 秒,但也不起作用 我应该如何解决它?

最佳答案

因此,使用引用站点和谷歌缓存可以帮助您避免这些失败。所以你的代码应该是:

# here added a referer
header = {"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36" ,'referer':'https://www.google.com/'}
# now use a google cache
r = requests.get("http://webcache.googleusercontent.com/search?q=cache:www.playerup.com/",headers=header)

现在查看状态代码:

>>>r
<Response [200]>

关于python - 响应 503 python 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61346381/

相关文章:

python - 如何将 pandas DataFrame 与内置逻辑连接起来?

python - 请求模块编码提供了与 HTML 编码不同的编码

python-3.x - Python - 请求、lxml 和 xpath 不起作用

python - 使用请求和 BeautifulSoup 下载文件

python-3.x - 从python中列表的元素中查找字符串中的字符

python - 以 Java 思维方式编写 Python 代码

c++ - SWIG C++ 到 Python:将 std::list 作为参数返回给 Python

python - 如何避免 Theano 计算梯度趋向于 NaN

python - python的空白问题

python-3.x - Monkeypatch setenv 值在 python unittest 中跨测试用例持续存在