Python请求:方法不允许错误

时间:2017-12-11 07:59:43

标签: python python-requests

我正在尝试使用requests.get()访问this网址,但它会提供 405 。通过浏览器访问时没有这样的问题。

2 个答案:

答案 0 :(得分:1)

我添加了所需的正确标头,试试这个

import requests

headers = {
                "Host": "www.propertyshark.com",
                "Connection": "keep-alive",
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36",
                "Upgrade-Insecure-Requests": "1",
                "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
                "Accept-Encoding": "gzip, deflate, br",
                "Accept-Language": "en-US,en;q=0.9",
}

url = "https://www.propertyshark.com/mason/Property/53047525/1302-Richland-Ave-Santa-Ana-CA-92703/"

req = requests.get(url, headers=headers)
print(req.status_code)

答案 1 :(得分:-1)

只是猜测,可能是因为您试图直接访问该页面。

您可以尝试添加引荐网址吗? my_referer是网站主页的网址

requests.get(url,headers = {'referer':my_referer})