想玩一玩 pytube,发现 vscode 终端好像没有走代理

59 天前
 Kakarrot

clash 打开 Allow Lan\Tun Mode\System Proxy

在 vscode 设置中设置http:Proxy:http://127.0.0.1:7890

# !/usr/bin/python3
# encoding=utf-8

from pytube import YouTube
from pytube.exceptions import VideoUnavailable

video = YouTube("https://www.youtube.com/watch?v=tO_L8bik10k")

print("Video_title = " + video.title)

try:
    print(video.streams)
    print(video.title)
except VideoUnavailable:
    print("视频不可用")
except Exception as e:
    print(f"发生错误: {e}")

为什么 title 可以打印出来,但是 streams 无法打印,并且返回发生错误: HTTP Error 400: Bad Request

试了一下在 vscode 终端 ping youtube.com 连接超时

1426 次点击
所在节点    Visual Studio Code
6 条回复
xinhaih
59 天前
能返回 title 和 http error 就说明已经走代理了,streams 无法打印应该有其他的问题。另外 ping 使用 icmp 协议不走 http 代理。
ZekeRuan
59 天前
我觉得是没有走代理,clash 无法代理系统层面,用软路由应该可以解决,而且谷歌系网站都不接受 icmp
fgt1t5y
59 天前
用 clash 的 tun 模式试试
Vegetable
59 天前
哥们儿们写代码甚至不愿意看一眼文档吗
Vegetable
59 天前
Kakarrot
59 天前

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1059168

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX