Python请求:方法不允许错误 [英] Python requests: Method not allowed error

查看:41
本文介绍了Python请求:方法不允许错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问 this URL 通过使用 requests.get() 但它给出 405.浏览器访问时无此问题.

I am trying to access this URL by using requests.get() but it gives 405. No such issue when accessing via browser.

推荐答案

我已经添加了所需的正确标题,试试这个

I have added the proper headers required, try this

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)

这篇关于Python请求:方法不允许错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆