![](/img/trans.png)
[英]Why am I getting the error: AtributeError: __enter__ when using requests.get() in `with` statement
[英]Why am I getting a [403] Error when trying to use requests.get in Python
我是 python 的新手,正在嘗試構建數據抓取工具。
嘗試運行時:
schedule_data = requests.get('https://nsmmhl.goalline.ca/schedule.php?league_id=264&from_date=2019-09-12&to_date=2020-02-02')
我得到:
<bound method Response.raise_for_status of <Response [403]>>
誰能告訴我為什么? 該鏈接工作正常。
設置請求的 header 屬性
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/80.0.3987.149 Safari/537.36'
}
schedule_data = requests.get(
'https://nsmmhl.goalline.ca/schedule.php?league_id=264&from_date=2019-09-12&to_date=2020-02-02',
headers=headers
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.