Example #1
0
    def test_proxy(self):
        geo_proxy = '127.0.0.1:{0}'.format(self.geo_port)
        ydl = YoutubeDL({
            'proxy': '127.0.0.1:{0}'.format(self.port),
            'geo_verification_proxy': geo_proxy,
        })
        url = 'http://foo.com/bar'
        response = ydl.urlopen(url).read().decode('utf-8')
        self.assertEqual(response, 'normal: {0}'.format(url))

        req = compat_urllib_request.Request(url)
        req.add_header('Ytdl-request-proxy', geo_proxy)
        response = ydl.urlopen(req).read().decode('utf-8')
        self.assertEqual(response, 'geo: {0}'.format(url))
Example #2
0
 def test_proxy_with_idn(self):
     ydl = YoutubeDL({
         'proxy': '127.0.0.1:{0}'.format(self.port),
     })
     url = 'http://中文.tw/'
     response = ydl.urlopen(url).read().decode('utf-8')
     # b'xn--fiq228c' is '中文'.encode('idna')
     self.assertEqual(response, 'normal: http://xn--fiq228c.tw/')