推荐学习书目
› 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
picy
V2EX  ›  Python

刚接触 python,有些关于 http 请求的东西搞不定.

  •  
  •   picy · Jan 5, 2017 · 2689 views
    This topic created in 3561 days ago, the information mentioned may be changed or developed.

    现在 python 哪个请求库支持类似这样的 header ?

    大部分的 header 都是通过 dict 封装的,

    多个重复的 header 没法子传啊。

    
    POST /api/xxx/xxxx HTTP/1.1
    Cust-Header: cookie_line_1
    Cust-Header: cookie_line_2
    Cust-Header: cookie_line_3
    Cust-Header: cookie_line_4
    Content-Type: application/x-www-form-urlencoded; charset=UTF-8
    User-Agent: Dalvik/2.1.0 (Linux; U; Android 6.0.1; SM-G9200 Build/MMB29K)
    Host: xxx.xxx.com
    Connection: Keep-Alive
    Accept-Encoding: gzip
    Content-Length: 926
    
    
    6 replies  •  2017-01-07 01:13:55 +08:00
    mymusise
        1
    mymusise  
       Jan 5, 2017
    推荐 requests

    import request
    headers = {
    "Cust-Header": "cookie_line_1",
    "Cust-Header": "cookie_line_2",
    "Cust-Header": "cookie_line_3",
    "Cust-Header": "cookie_line_4",
    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
    "User-Agent": "Dalvik/2.1.0 (Linux; U; Android 6.0.1; SM-G9200 Build/MMB29K)",
    "Host": "xxx.xxx.com",
    "Connection": "Keep-Alive",
    "Accept-Encoding": "gzip",
    "Content-Length": "926"
    }

    url = ""

    requests.post(url, headers=headers)
    picy
        2
    picy  
    OP
       Jan 5, 2017
    @mymusise 传入的还是 dict ,会被覆盖掉的
    mymusise
        4
    mymusise  
       Jan 6, 2017
    @janstk 哦,你是这个意思,不过
    Cust-Header: cookie_line_1
    Cust-Header: cookie_line_2
    Cust-Header: cookie_line_3
    Cust-Header: cookie_line_4
    不等效于
    Cust-Header: cookie_line_1 , cookie_line_2,cookie_line_3,cookie_line_4 么?
    picy
        5
    picy  
    OP
       Jan 7, 2017
    @mymusise 服务器不知道做了什么脑残的东西,没有按 http 协议走,分开传。
    picy
        6
    picy  
    OP
       Jan 7, 2017
    @Contextualist 感谢,没想到 header 的 value 还能带换行。哈哈哈哈。受教了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2570 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:43 · PVG 22:43 · LAX 07:43 · JFK 10:43
    ♥ Do have faith in what you're doing.