HTTP 503 Error while using python requests module

感情迁移 提交于 2020-07-22 05:37:05

问题


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)

回答1:


503 means the server is overloaded: https://httpstatuses.com/503

This is not an issue with your code, it is an issue with the server you are trying to access.




回答2:


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()

Found from this site



来源:https://stackoverflow.com/questions/47910854/http-503-error-while-using-python-requests-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!