python请求<Response[403]>即使在添加useragen之后

2022-05-21 07:58:56 发布

您现在位置:Python中文网/ 问答频道 /正文

即使在添加了user-agent头之后,我也得到了get请求的<Response [403]>

这是我的密码:

import requests

url = 'https://www.malacards.org/categories/blood_disease_list'

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36'}

r = requests.get(url, headers)

print(r)

Tags: httpsorgimporturl密码getresponsewwwrequestsagentheaderscategoriesuserbloodmalacards
1条回答
网友
1楼 ·

您需要以kwarg形式传递标题:

r = requests.get(url, headers=headers)

signature of ^{}是:

def get(url, params=None, **kwargs):

如果不将其作为kwarg传递,Python会假定您的意思是params = headers