使用python请求模块时出现HTTP 503错误 [英] HTTP 503 Error while using python requests module
本文介绍了使用python请求模块时出现HTTP 503错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试发出HTTP请求,但是我当前可以从Firefox浏览器响应503错误访问的网站.代码本身非常简单.在网络中进行一些搜索后,我添加了user-Agent
参数以进行请求,但它也无济于事.有人可以向我解释如何摆脱此503错误吗?
顺便说一句,我想根据btc的价格制作自己的警报系统.
I'm trying to make a HTTP request but the website that I currently can reach from my Firefox browser response 503 error. Code itself is really simple. After some search in the net I added user-Agent
parameter to request but it didn't help either. Can someone explain me how to get rid of this 503 error?
Btw I want to make my own alert system based on prices of btc.
import requests
url = "https://www.paribu.com"
header ={'User-Agent': 'Mozilla/5.0 (Windows NT x.y; Win64; x64; rv:10.0) Gecko/20100101 Firefox/10.0 '}
response = requests.get(url,headers = header)
print(response)
推荐答案
我遇到了同样的问题.在您的代码中使用它.
I had the same problem. Use this in your code.
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36',}
r = requests.post(url, headers=headers)
r.raise_for_status()
这篇关于使用python请求模块时出现HTTP 503错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文