V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
cy1027
V2EX  ›  Python

Python 代理问题, requests 自带的 proxies 参数会导致请求失败

  •  
  •   cy1027 · 2022-08-02 15:11:15 +08:00 · 2132 次点击
    这是一个创建于 595 天前的主题,其中的信息可能已经有所发展或是发生改变。

    一个请求通过 fiddler 走了代理,能请求,但是另一个用 requests 自带的配置走代理请求,就失败 有大佬知能给指点指点不?

    9 条回复    2022-08-03 07:40:20 +08:00
    cy1027
        1
    cy1027  
    OP
       2022-08-02 15:13:17 +08:00
    我两次请求用了同样的其它参数,唯一不同的就是一个请求用 requests 自带的 proxies 添加了代理,另外一个用 fiddler 的 gateway 功能走了代理,两种方式走的是同一个代理
    dicc
        2
    dicc  
       2022-08-02 18:07:36 +08:00
    你代码写错了
    tanjnr
        3
    tanjnr  
       2022-08-02 19:37:01 +08:00 via iPhone
    你代码写错了+1
    hlpureboy
        4
    hlpureboy  
       2022-08-02 19:41:06 +08:00
    估计代码写错惹
    whattime
        5
    whattime  
       2022-08-02 19:44:15 +08:00
    http_proxy = "http://127.0.0.1:1081"
    https_proxy = "http://127.0.0.1:1081"
    ftp_proxy = "ftp://127.0.0.1:1081"

    proxyDict = {
    "http" : http_proxy,
    "https" : https_proxy,
    "ftp" : ftp_proxy
    }
    610915518
        6
    610915518  
       2022-08-02 20:43:22 +08:00
    无代码无真相
    mekingname
        7
    mekingname  
       2022-08-02 22:40:56 +08:00
    他肯定是把 https 的代理的 scheme 写成 https 了。大多数代理网站都不提供 https 的代理。requests 的 proxies 字典里面,https 这个 key 对应的 value ,也应该是 http://开头。
    nyxsonsleep
        8
    nyxsonsleep  
       2022-08-02 23:17:17 +08:00
    @mekingname #7 我印象中是 python 不同库有好几种写法。
    比如不能加 http 头的 proxy 。都要 http 头的 proxy 。分别要 http 和 https 头的 proxy 。
    kokutou
        9
    kokutou  
       2022-08-03 07:40:20 +08:00 via Android
    我记得有个 bug 被修了,Python 和包都更新最新,然后再试试?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3401 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 11:43 · PVG 19:43 · LAX 04:43 · JFK 07:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.