• Python 3.x HTTP Error 403: Forbidden


    The Fobidden error often raised when using request.open to open some urls.

    such as:

    url_1 = 'https://movie.douban.com/subject/26363254/comments?status=P'
    url_2 = 'https://www.glassdoor.com/Interview/Texas-Instruments-Interview-Questions-E651_P4.htm'

    request.urlopen(url_1) # ** no error raised

    request.urlopen(url_2) # ** Fobidden error raised

    Here is the reason:

    When using urllib.request.urlopen to visit a URL, the server will only receive a simple request for this webpage without knowing the hidden infos about exploer,operating system,platform, which are abnormal. 

    Some websited will vefify the UserAgent info to prevent the abnoraml visisting. 

    So the solution : Add these infos to the UserAgent to acts as using exploer to visit

    req = request.Request(url,headers={'User-Agent': 'Mozilla/5.0'}) # ** this would fix, also you can add other infos to User-Agent

  • 相关阅读:
    15 手写数字识别-小数据集
    14 深度学习-卷积
    5.线性回归算法
    9、主成分分析
    8、特征选择
    4.K均值算法--应用
    6.逻辑回归
    12.朴素贝叶斯-垃圾邮件分类
    13、垃圾邮件2
    大数据应用期末总评
  • 原文地址:https://www.cnblogs.com/szzshi/p/7388963.html
Copyright © 2020-2023  润新知