推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
cdwyd
V2EX  ›  Python

python requests 无法获取 youtube 的内容

  •  
  •   cdwyd · Jan 7, 2015 · 3937 views
    This topic created in 4177 days ago, the information mentioned may be changed or developed.
    RT,代码如下:

    import requests

    session = requests.session()
    session.proxies = {'http': '127.0.0.1:8123'}
    timeout = 20
    url = 'http://www.youtube.com'

    html = session.get(url, timeout = timeout).text

    之前一直用的好好的,找了半天也没找到原因,为什么就获取不到了
    Supplement 1  ·  Jan 7, 2015
    错误信息:
    (<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x01EF4EB0>, 'Connection to www.youtube.com tim
    ed out. (connect timeout=20)')
    Supplement 2  ·  Jan 7, 2015
    刚又继续测试了下,http的都能打开,https的都无法打开
    youtube是强制使用https的吗?
    11 replies    2015-01-07 15:29:15 +08:00
    ultimate010
        1
    ultimate010  
       Jan 7, 2015   ❤️ 1
    本地开的http代理能用吗?
    cdwyd
        2
    cdwyd  
    OP
       Jan 7, 2015
    @ultimate010
    能用,访问别的都是正常的
    ultimate010
        4
    ultimate010  
       Jan 7, 2015
    你把youtube.com改成其他网站,试一试,如果可以,就是你的代理不能访问youtube.com
    iewgnaw
        5
    iewgnaw  
       Jan 7, 2015
    错误信息都不贴出来吗
    binux
        6
    binux  
       Jan 7, 2015
    什么叫:无法获取?获取不到?
    cdwyd
        7
    cdwyd  
    OP
       Jan 7, 2015
    @binux
    运行后没反应,一段时间后提示timeout
    Sylv
        8
    Sylv  
       Jan 7, 2015
    >>> import requests
    >>> r = requests.get('http://www.youtube.com')
    >>> r.url
    u'https://www.youtube.com/'
    >>> r.history
    [<Response [301]>]
    >>> r.history[0].headers['location']
    'https://www.youtube.com/'
    ryd994
        9
    ryd994  
       Jan 7, 2015
    @cdwyd timeout这是典型被墙啊
    yegle
        10
    yegle  
       Jan 7, 2015 via Android
    因为你设置的是HTTP的代理服务器,youtube首页会301跳转到HTTPS。
    thinker3
        11
    thinker3  
       Jan 7, 2015
    @yegle 貌似正确
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5531 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 06:57 · PVG 14:57 · LAX 23:57 · JFK 02:57
    ♥ Do have faith in what you're doing.