python - 响应 [403] 添加用户代理和其他标头后 Python 请求出错,Cloudfare 阻止访问
问题描述
尽管添加了从 chrome 开发人员工具获得的标头,但我还是多次收到 <Response [403]>。有更多经验的人能否告诉我是否可以使用 Python 请求访问以下 url?如果没有,是否有建议的替代方法
url='https://www.phosphosite.org/proteinAction.action?id=5848&showAllSites=true'
from bs4 import BeautifulSoup
import requests
url='https://www.phosphosite.org/proteinAction.action?id=5848&showAllSites=true'
headers={'user-agent': 'Mozilla/5.0....'}
result = requests.get(url, headers=headers)
print(result.request.headers)
print(result)
解决方案
因为header key是小写的 怎么解决? 更改您的标题键:
'user-agent'
至:
'User-Agent'
然后你得到<Response [200]>
结果。
推荐阅读
- angularjs - Angular UI Router:1 转换身份验证、授权和基于角色的检查
- flexbox - 动态网格数据的 Angular Flex 布局性能
- ios - 从 CoreBlutooth 重新启动应用程序 - didUpdateValueForCharacteristic 函数
- reactjs - reactjs在播放时更改音频的currentTime
- css - 导航栏不完全透明
- javascript - 用新内容替换特定的 dom 元素
- python - 芹菜:禁用工人之间的心跳
- python - django.db.models.fields.related_descriptors.RelatedObjectDoesNotExist:
- c++ - rapidjson + c++:“abort() 已被调用”错误
- function - 栅格气候数据(qmap)的偏差校正 - 公式中的错误