求助如何删除 requests 中的某些 header - 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
alvin666

求助如删除 requests 中的某些 header

  •  
  •   alvin666 Aug 18, 2018 7635 views
    This topic created in 2826 days ago, the information mentioned may be changed or developed.

    抓包安卓 app,发现实际请求的 header 是

    Content-Type: application/x-www-form-urlencoded; charset= token: sasasasasasasasasasas Host: ********:8443 Connection: Keep-Alive 

    用 requests 模拟,添加上述 header 以后,发现实际发送的请求经过 requests 处理,header 增加了几项(带*的)

    *User-Agent: python-requests/2.19.1 *Accept-Encoding: gzip, deflate *Accept: */* Connection: Keep-Alive Content-Type: application/x-www-form-urlencoded; charset= Host: *******:8443 *Content-Length: 0 token: sasasasasasasasasasas 

    求助怎么完全自定义 requests 的 header,或者删除 header 中的某些项,文档中没找见....

    9 replies    2018-08-18 16:56:51 +08:00
    julyclyde
        1
    julyclyde  
       Aug 18, 2018
    不能删除
    你可以覆盖掉它
    alvin666
        2
    alvin666  
    OP
       Aug 18, 2018 via Android
    @julyclyde 是可以覆盖,比如模拟浏览器操作的时候,header 换成 Chrome,然而这个是 app 的请求,万一服务端来个 header 过滤就 gg...
    kmahyyg
        3
    kmahyyg  
       Aug 18, 2018 via iPad
    ```python
    custom_headers={"user-agent": "", ......}
    r = requests.get(url, headers=custom_headers}
    ```

    请参考文档
    alvin666
        4
    alvin666  
    OP
       Aug 18, 2018 via Android
    @kmahyyg 我就是这么做的,但是只能覆盖,如果值空白,发送的请求里面也有,不能删除已有的 cookie,文档里面没有提到我才来问的,谢谢
    stamaimer
        5
    stamaimer  
       Aug 18, 2018 via iPhone
    None
    alvin666
        6
    alvin666  
    OP
       Aug 18, 2018 via Android
    @stamaimer 详细说说?....意思是没办法?
    holajamc
        7
    holajamc  
       Aug 18, 2018   2
    @alvin666
    @stamaimer 的意思是这样
    import requests

    proxies = {
    "http": "http://127.0.0.1:8888",
    "https": "http://127.0.0.1:8888",
    }
    headers = {'User-Agent': None}
    requests.get("http://example.org", headers=headers, proxies=proxies)
    alvin666
        9
    alvin666  
    OP
       Aug 18, 2018 via Android
    @Xiaobaixiao @holajamc 谢谢!最近被墙的厉害,没仔细在谷歌上面找,感谢!
    About     Help     Advertise     Blog     API     FAQ     Solana     3285 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 57ms UTC 13:38 PVG 21:38 LAX 06:38 JFK 09:38
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86