zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    oracle用户和权限
    oracle中的索引
    oracle中的序列
    oracle中的视图
    oracle PL/SQL块
    oracle创建表案列
    半导体随机存储器
    IEEE754标准
    定点数的移位操作
    真值,原码,反码以及补码和移码总结
  • 原文地址:https://www.cnblogs.com/szzshi/p/7388963.html
Copyright © 2011-2022 走看看